-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_image.py
34 lines (30 loc) · 943 Bytes
/
read_image.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
from pytesseract import image_to_string
import cv2 as cv
import numpy as np
class Read_image:
@classmethod
def read_image(cls, img):
custom_config = r'--oem 1 --psm 8 outputbase digits'
txt = image_to_string(img, config=custom_config)
# cv.imshow("Tess Img", img)
# Read_image.test(txt)
# cv.waitKey(500)
# cv.destroyAllWindows()
return txt
@classmethod
def test(cls, txt):
img = np.zeros((50,50,3), np.uint8)
# Write some Text
font = cv.FONT_HERSHEY_SIMPLEX
bottomLeftCornerOfText = (10,40)
fontScale = 1
fontColor = (255,255,255)
lineType = 2
cv.putText(img,txt,
bottomLeftCornerOfText,
font,
fontScale,
fontColor,
lineType)
#Display the image
cv.imshow("img",img)