-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOCR_Image.py
49 lines (35 loc) · 1.05 KB
/
OCR_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import cv2
import sys
import pytesseract
if __name__ == '__main__':
print("Enter name to search: ")
name = input()
nameList = []
found = 0
count = 0
i = 0
vid = cv2.VideoCapture('video0.mp4')
while(vid.isOpened()):
ret, frame = vid.read()
count = (count+1)%100
i = i+1
if count==1:
# Uncomment the line below to provide path to tesseract manually
# pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
# Define config parameters.
# '-l eng' for using the English language
# '--oem 1' for using LSTM OCR Engine
config = ('-l eng --oem 1 --psm 11')
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = cv2.bitwise_not(gray)
# Run tesseract OCR on image
text = pytesseract.image_to_string(frame, config=config)
text = text.replace("\n\n","\n")
nameList = text.split("\n")
cv2.imwrite('frame' + str(i) + '.jpg',frame)
if name in nameList:
print("Yes")
found = 1
break
if not found:
print("No")