I was trying to process a video where I have digits that I want to digitalize. I've copied the code from another answer in here, How can I extract numbers from video frames using Tesseract OCR?, the thing is I can't make it work.
I tried the following code
import cv2
import pytesseract
def getText(filename):
img = cv2.imread(filename)
HSV_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(HSV_img)
v = cv2.GaussianBlur(v, (1,1), 0)
thresh = cv2.threshold(v, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
cropped_thresh = thresh[120:410, 300:800]
cv2.imwrite('{}.png'.format(filename),cropped_thresh)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, ksize=(1, 2))
cropped_thresh = cv2.dilate(cropped_thresh, kernel)
txt = pytesseract.image_to_string(cropped_thresh, config='--psm 6 digits')
return txt
Here is the original frame of the video
Here is the image before the image_to_string function.
edit: In this image I upload as an example I get as output 17
, whereas I want to get 7.7
or at least 77
. Also I have very similar images with the same digits, and I get different outputs. For example, the next frame which is identical I get 717
and 4
.