backend/photo_log/autocrop/ocr.py

16 lines
550 B
Python
Executable File

################################################################
##### OCR
################################################################
gray = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2GRAY)
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
gray = cv2.medianBlur(gray, 3)
cv2.imwrite("debug_out/bin.png", gray)
img = Image.fromarray(cropped_image)
tessdata_dir_config = r'--tessdata-dir "./ocr_langs"'
text = pytesseract.image_to_string(gray, lang='deu-best', config=tessdata_dir_config)
print(text)