-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetected.py
34 lines (30 loc) · 1.21 KB
/
detected.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytesseract
import cv2
img = cv2.imread('data/data.png')
# img = cv2.resize(img, (600, 360))
hImg, wImg, _ = img.shape
pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
boxes = pytesseract.image_to_boxes(img)
for b in boxes.splitlines():
b = b.split(' ')
print(b)
x, y, w, h = int(b[1]), int(b[2]), int(b[3]), int(b[4])
cv2.rectangle(img, (x, hImg - y), (w, hImg - h), (50, 50, 255), 1)
cv2.putText(img, b[0], (x, hImg - y + 13),
cv2.FONT_HERSHEY_SIMPLEX, 0.4, (50, 205, 50), 1)
cv2.imshow('Detected text', img)
cv2.waitKey(0)
def detectedText(loc):
img = cv2.imread(loc)
hImg, wImg, _ = img.shape
pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
boxes = pytesseract.image_to_boxes(img)
for b in boxes.splitlines():
b = b.split(' ')
print(b)
x, y, w, h = int(b[1]), int(b[2]), int(b[3]), int(b[4])
cv2.rectangle(img, (x, hImg - y), (w, hImg - h), (50, 50, 255), 1)
cv2.putText(img, b[0], (x, hImg - y + 13),
cv2.FONT_HERSHEY_SIMPLEX, 0.4, (50, 205, 50), 1)
cv2.imwrite('temp/boxes_with_names.jpg', img)
cv2.waitKey(0)