![](/img/trans.png)
[英]how to extract a particular frame from video stream using Opencv & Python
[英]How can extract text from video stream?
我正在尝试使用opencv2和pytesseract从我的相机中提取视频流中的一些文本。 我裁剪图像以获得另一个小图像。 我托盘不同的图像处理,以使其工作。 我将图像值反转,模糊,将其二值化,但这些都没有使用tesseract。 我要提取的数据有这些形式'float / float'这里是小图像的示例:
好像字符没有分开,这是我从相机中获得的最大分辨率。 我尝试按颜色过滤,但没有结果,因为它是视频,背景总是在移动。 我将使用任何可以工作的建议Python模块。
看起来并不琐碎。 我为每个角色生成了32x32 png图像并为其添加了白噪声。 视频背景正在移动。 和8和6这样的字符差别不大。 这是我目前的代码:
cap = cv2.VideoCapture("rtsp:...")
time.sleep(2)
templates = {}
w=[]
h=[]
for i in range(0,11):
templates["template_"+str(i)]=cv2.imread(str(i)+'.bmp',0)
tmp_w,tmp_h=templates["template_"+str(i)].shape[::-1]
w.append(tmp_w)
h.append(tmp_h)
threshold = 0.70
while(True):
les_points=[[],[],[],[],[],[],[],[],[],[],[]]
ret, frame = cap.read()
if frame==None:
break
crop_image=frame[38:70,11:364]
gray=cv2.cvtColor(crop_image,cv2.COLOR_BGR2GRAY)
for i in range(0,11):
res= cv2.matchTemplate(gray,templates["template_"+str(i)],cv2.TM_CCOEFF_NORMED)
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
les_points[i].append(pt[0])
cv2.rectangle(crop_image, pt, (pt[0] + w[i], pt[1] + h[i]), (0,i*10,255), 2)
print les_points
cv2.imshow('normal',crop_image)
if cv2.waitKey(1)& 0xFF == ord('p'):
threshold=threshold+0.01
print threshold
if cv2.waitKey(1)& 0xFF == ord('m'):
threshold=threshold-0.01
print threshold
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我正在做其他测试,将图像拆分为模板中caracters完全相同的大小。 但这并没有给出好的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.