/
rnekrasov
/
Python
Обзор
Документация
Войти
/
rnekrasov
/
Python
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Extract_Text_from_image.py
20 строк
624 B
slowy07
refactor: clean code
30 янв 2022, 04:33
30 янв 2022, 04:33
f0af0c4
Код
Авторство
О чём код?
# extract text from a img and its coordinates using the pytesseract module import cv2 import pytesseract # You need to add tesseract binary dependency to system variable for this to work img = cv2.imread("img.png") # We need to convert the img into RGB format img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) hI, wI, k = img.shape print(pytesseract.image_to_string(img)) boxes = pytesseract.image_to_boxes(img) for b in boxes.splitlines(): b = b.split(" ") x, y, w, h = int(b[1]), int(b[2]), int(b[3]), int(b[4]) cv2.rectangle(img, (x, hI - y), (w, hI - h), (0, 0, 255), 0.2) cv2.imshow("img", img) cv2.waitKey(0)