-
Notifications
You must be signed in to change notification settings - Fork 2
/
text_detection.py
44 lines (41 loc) · 1.36 KB
/
text_detection.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
import cv2
from imageai.Detection import ObjectDetection
from moviepy.editor import VideoFileClip
import os
from PIL import Image
import pytesseract
proxy = 'http://edcguest:[email protected]:3128'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
def convert_to_photo_text(filepath, keyword):
print(cv2.__version__)
filepath = './static/images/video_text.mp4'
vidcap = cv2.VideoCapture(filepath)
success,image = vidcap.read()
count = 0
success = True
clip = VideoFileClip(filepath)
clipDuration = clip.duration;
while success:
vidcap.set(cv2.CAP_PROP_POS_MSEC,(count*9000))
cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
success,image = vidcap.read()
print ('Read a new frame: ', success)
count += 1
clipDuration /= count;
frameTime = []
finalTime = []
for i in range (count):
frameTime.append(i*clipDuration);
print(frameTime)
execution_path = os.getcwd()
for i in range (count):
text = pytesseract.image_to_string(Image.open("frame%d.jpg" % i), lang = "eng")
print(text.lower())
if keyword in text.lower():
finalTime.append(frameTime[i])
print(finalTime)
return finalTime
# convert_to_photo_text("video_text.mp4", "hashes")