-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (44 loc) · 1.88 KB
/
main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import cv2
import pytesseract
# pytesseract.pytesseract.tesseract_cmd ='tesseract-ocr-w64-setup-5.3.1.20230401.exe'
webcam = cv2.VideoCapture(0)
if webcam.isOpened() == False:
print('error opening the webcam')
try:
while webcam.isOpened():
ret, frame = webcam.read()
if ret == True:
imgH ,imgW,_ = frame.shape
x1,y1,w1,h1 = 0,0,imgH ,imgW
imgchar = pytesseract.image_to_string(frame)
imgboxes = pytesseract.image_to_boxes(frame)
for boxes in imgboxes.splitlines():
boxes = boxes.split(' ')
x,y,w,h = int(boxes[1]),int(boxes[2]),int(boxes[3]),int(boxes[4])
cv2.rectangle(frame,(x,imgH-y),(w,imgH-h),(0,0,255),3)
cv2.putText(frame,imgchar,(x1 +int(w1/50),y1+int(h1/50)),cv2.FONT_HERSHEY_COMPLEX,0.7,(0,0,255),2)
cv2.imshow('text',frame)
cv2.waitKey(1)
else:
break
except KeyboardInterrupt:
pass
webcam.release()
# license_color = cv2.cvtColor(carplate_extract_img, cv2.COLOR_BGR2GRAY)
# carplate_extract_img_colored = cv2.medianBlur(license_color, 3)
# _, license = cv2.threshold(carplate_extract_img_colored, 120, 255, cv2.THRESH_BINARY)
# from PIL import Image
# plate = "L21lZGlhLXBhL1dWMTcvMS80L1dWMTcxNDM1NTgyXzEuanBlZw_rct"
# img = cv2.imread(f'./{plate}.webp',cv2.COLOR_BGR2GRAY)
# imgH ,imgW,_ = img.shape
# x1,y1,w1,h1 = 0,0,imgH ,imgW
# imgchar = pytesseract.image_to_string(img)
# imgboxes = pytesseract.image_to_boxes(img)
# for boxes in imgboxes.splitlines():
# boxes = boxes.split(' ')
# x,y,w,h = int(boxes[1]),int(boxes[2]),int(boxes[3]),int(boxes[4])
# cv2.rectangle(img,(x,imgH-y),(w,imgH-h),(0,0,255),3)
# cv2.putText(img,imgchar,(x1 +int(w1/50),y1+int(h1/50)),cv2.FONT_HERSHEY_COMPLEX,0.7,(0,0,255),2)
# print(pytesseract.image_to_string(img))
# cv2.imshow('Result',img)
# cv2.waitKey(0)