首页新闻找找看学习计划

opencv+python 实时显示文字的问题

0
悬赏园豆:30 [待解决问题]

-- coding: utf-8 --

"""
Created on Fri Feb 8 21:19:31 2019

@author: chengzhean
"""

import array
from skimage import io,transform
import glob
import os
import tensorflow as tf
import numpy as np
import time
import cv2, numpy as np
import matplotlib.pyplot as plt
from array import
import numpy as np
import scipy.misc
from tkinter import

from tkinter import messagebox
import tkinter.filedialog as filedialog
from PIL import Image, ImageTk
import imutils

def test(path):
dict = {0:'右脸' ,
1:'左脸' ,
2:'正脸'}

w=100
h=100 
c=3
def read_one_image(path):
    img = io.imread(path)
    img = transform.resize(img,(w,h,c))
    return np.asarray(img)

with tf.Session() as sess:
    data = []
    data1 = read_one_image(path)
    data.append(data1)    
    saver = tf.train.import_meta_graph('./model/model_flower.ckpt.meta')
    saver.restore(sess,tf.train.latest_checkpoint('./model/'))

    graph = tf.get_default_graph()#获取图像
    x = graph.get_tensor_by_name("x:0")#获得图像的张量
    feed_dict = {x:data}#生成一个字典,把数据和图像对应
    logits = graph.get_tensor_by_name("logits_eval:0")
    classification_result = sess.run(logits,feed_dict)#开始预测
    #打印出预测矩阵
    #print(classification_result)
    #打印出预测矩阵每一行最大值的索引
    #print(tf.argmax(classification_result,1).eval())#就是预测数概率最大的那个类别
    #根据索引通过字典对应故障的分类
    output = []
    output = tf.argmax(classification_result,1).eval()
    r = dict[output[0]]
    print(r)
    string = str('%s'%r)
    print('识别结果:',string)
    k=sess.run(tf.argmax(classification_result,1))


    if k[0]==2:
        cv2.putText(frame, "222", (10, 60),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
        cv2.putText(frame, "nosemouth: {:.2f}".format(k[0]), (300, 120),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

    elif k[0]==0:
        cv2.putText(frame, "000", (10, 60),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
        cv2.putText(frame, "mouthEAR: {:.2f}".format(k[0]), (300, 60),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

    else:
        cv2.putText(frame, "111", (10, 60),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

vc=cv2.VideoCapture(0)
c=1
if vc.isOpened():
rval,frame=vc.read()
else:
rval=False
F=24

while rval:
rval,frame=vc.read()
cv2.imshow("Frame", frame)
if (c % F == 0):
cv2.imwrite('./img/'+str(c)+'.jpg',frame)
path = './img/'+str(c)+'.jpg'
print('读入:',path)
test(path)
c=c+1
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
vc.release()

代码如上, cv2.putText()函数没有起作用,但程序确实进入了 if k[0]==2、elif k[0]==0、 else循环

lixt1的主页 lixt1 | 初学一级 | 园豆:172
提问于:2019-02-18 10:14
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册