Code qismi:
import re
from pprint import pprint
import cv2
import pytesseract
from pytesseract import Output
pytesseract.pytesseract.tesseract_cmd = """C:\Program Files\Tesseract-OCR\\tesseract.exe"""
img = cv2.imread('POSPORT.jpg')
d = pytesseract.image_to_data(img, output_type=Output.DICT)
keys = list(d.keys())
date_pattern = "Otasining"
n_boxes = len(d['text'])
for i in range(n_boxes):
if int(d['conf'][i]) > 60:
if re.match(date_pattern, d['text'][i]):
(x, y, w, h) = (d['left'][i], d['top'][i+8], d['width'][i+8], d['height'][i])
img = cv2.rectangle(img, (x - 2, y - 2), (x + w + 2, y + h + 2), (0, 255, 0), 2)
d['text'] = list(filter(None, d['text']))[15]
print(d['text'])
cv2.imshow('img', img)
cv2.waitKey(0)
Do'stlaringiz bilan baham: |