问题描述
我有很多漫画,我想使用网络摄像头提取它们的标题。我在下面做了代码:
import cv2
import numpy as np
import PyTesseract
from PIL import Image
from PyTesseract import Output
cam = cv2.VideoCapture(2)
cv2.namedWindow("test")
img_counter = 0
while True:
ret,frame = cam.read()
if not ret:
print("Failed to grab frame")
break
cv2.imshow("test",frame)
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit,closing...")
break
elif k%256 == 32:
# SPACE pressed
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name,frame)
print("{} written!".format(img_name))
image = cv2.imread(img_name)
im = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
img = Image.fromarray(im)
results = PyTesseract.image_to_data(img,lang='fra+eng',output_type=Output.DICT)
# loop over each of the individual text localizations
for i in range(0,len(results["text"])):
# extract the bounding Box coordinates of the text region from
# the current result
x = results["left"][i]
y = results["top"][i]
w = results["width"][i]
h = results["height"][i]
text = results["text"][i]
conf = int(results["conf"][i])
# filter out weak confidence text localizations
if conf > 50:
# display the confidence and text to our terminal
print("Confidence: {}".format(conf))
print("Text: {}".format(text))
print("")
text = "".join([c if ord(c) < 128 else "" for c in text]).strip()
cv2.rectangle(image,(x,y),(x + w,y + h),(0,255,0),2)
cv2.putText(image,text,y - 10),cv2.FONT_HERShey_SIMPLEX,1.2,255),3)
cv2.imshow("res",image)
#####################################
img_counter += 1
cam.release()
cv2.destroyAllWindows()
当我按“ SPACE”时,会拍下标题的照片,而tesseract会尝试提取一些文本。我做了下面的测试。
请问如何改善呢? (除非在书中找到用好字体写的标题:-))
欢呼
Karim
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)