Reputation: 460
I need to recognize digits on 7 seg clocks(see picture below), so I use following python code:
def detect_date(image: cv2.UMat, bbox:list) -> datetime:
gry1 = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thr1 = cv2.threshold(gry1, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
data = pytesseract.image_to_data(thr1, lang="7seg", config="--psm 6 digits", output_type= Output.DICT)
return data
I found 7seg train data here and used code chung
I test with this image -- . The problem is that retunr result of tesseract fn image_to_data is following:
{'level': [1, 2, 3, 4, 5], 'page_num': [1, 1, 1, 1, 1], 'block_num': [0, 1, 1, 1, 1], 'par_num': [0, 0, 1, 1, 1], 'line_num': [0, 0, 0, 1, 1], 'word_num': [0, 0, 0, 0, 1], 'left': [0, 15, 15, 15, 15], 'top': [0, 5, 5, 5, 5], 'width': [330, 300, 300, 300, 300], 'height': [70, 63, 63, 63, 63], 'conf': [-1, -1, -1, -1, 0], 'text': ['', '', '', '', '205215068']}
First of all, I don't understand why I got returned array of 5 items? What does it mean? Next, I don't understand confidence levels? Mathcing conf array with text it seems that properly recognized text( digits) have 0 confidence. Why is that? What I'm doing wrong?
If I use config="--psm 6" (omit digits parameter), then output is following:
{'level': [1, 2, 3, 4, 5, 5], 'page_num': [1, 1, 1, 1, 1, 1], 'block_num': [0, 1, 1, 1, 1, 1], 'par_num': [0, 0, 1, 1, 1, 1], 'line_num': [0, 0, 0, 1, 1, 1], 'word_num': [0, 0, 0, 0, 1, 2], 'left': [0, 15, 15, 15, 15, 179], 'top': [0, 5, 5, 5, 13, 5], 'width': [330, 300, 300, 300, 142, 136], 'height': [70, 63, 63, 63, 55, 54], 'conf': [-1, -1, -1, -1, 41, 30], 'text': ['', '', '', '', "'Z0S52Z", 'IS068']}
It has wrong recognitions but confidence make more sense now (at least not 0).
Can I got confidence for each digits or for whole string (numbers) only?
I'm quite new to OCR and tesseract so will be thankfull for any help and advices.
Thanks in advance.
Upvotes: 0
Views: 35