python识别文字 opencv_opencv+python 实时显示文字的问题

-- 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循环

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值