forked from RobertRen1122/NoteGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocking.py
28 lines (26 loc) · 922 Bytes
/
blocking.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
# initialization
import pytesseract
# pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
from PIL import Image
import cv2
def find_word(directory):
resDict = pytesseract.image_to_boxes(Image.open(directory), lang='eng')
return resDict
if __name__ == '__main__':
# import the picture directory
directory = "test.jpg"
dict = find_word(directory).splitlines()
#x, y, w, h
# draw_rect(directory)
image = cv2.imread(directory)
hImg, wImg, _ = image.shape
for x in range(len(dict)):
dict[x] = dict[x].split(" ")
start_point = (int(dict[x][1]), hImg - int(dict[x][2]))
end_point = (int(dict[x][3]), hImg - int(dict[x][4]))
thickness = 2
color = (255, 0, 0)
image = cv2.rectangle(image, start_point, end_point, color, thickness)
cv2.imshow("hi", image)
cv2.waitKey(0)
cv2.destroyWindow("hi")