Reputation: 41
I'm traying to extract some text from video stream coming from my camera using opencv2 and pytesseract. I crop the image to get an other small image. I trayed different image processing to get it work. I inverted the image values, blur it, binarize it, but no one of these is working with tesseract. The data that I want to extract has these form 'float/float' here is example of the small image:
Seems like the characters are not separated and this is the maximum resolution that I can get from my camera. I tried then to filter by color, but no result because it is video and the background is always moving. I will use any suggested Python module that can work.
Upvotes: 3
Views: 6026
Reputation: 41
not trivial as it seems. i generated 32x32 png image for every character and add a white noise to it. the backgound on the video is moving. and caracters like 8 and 6 are not very different. here is my code for the moment:
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
I'm doing other tests by split the image to the exact same size of the caracters in templates. but this is not giving good results
Upvotes: 1