本帖最后由 dfcxfy 于 2018-4-16 08:51 编辑
通过USB摄像头读取图片。为了提过识别率把图片做了灰度转换(我增加锐边的效果反而不好了,可能我的设置有问题,理论上应该是可以提高识别率的)
拍照的程序:
# coding:utf-8
import cv2
import sys
reload(sys)
sys.setdefaultencoding('utf8')
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
cap.set(1, 10.0)
i=1
while(1):
i=i+1
ret,frame = cap.read()
cv2.imshow('capture', frame)
if i==20:
cv2.imwrite('2.jpg', frame)
break
cap.release()
#out.release()
cv2.destroyAllWindows()
主程序:
#encoding:utf-8
import os
import sys
import codecs
import cv2
import time
from aip import AipOcr
APP_ID = '百度id'
API_KEY = '百度API_KEY '
SECRET_KEY = '百度SECRET_KEY'
f = codecs.open(r"E:\python\rennian.txt", "w",'utf-8')
os.system(r'E:\python\zhaopian.py')
aipFace =AipOcr(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
im_gray = cv2.imread("2.jpg",cv2.IMREAD_GRAYSCALE)
cv2.imwrite("test.png",im_gray)
image = get_file_content("test.png")
result = aipFace.basicGeneral(image)
i=result['words_result_num']
zi= result['words_result']
a=0
while True:
if a==i:
break
else:
b= zi[a]['words']
print b
a =a+1
f.write(b+'\r\n')
|