-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvideoAnalysis.py
36 lines (27 loc) · 1.09 KB
/
videoAnalysis.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
import cv2
import numpy as np
from PIL import Image
import imagehash
def videoAnalysis(FRAMES_SKIP, VIDEO_PATH):
vid= cv2.VideoCapture(VIDEO_PATH)
f= open('frameHashData.txt', 'w', buffering=1) # For storing and analysing frame hash differences
success, prevImg= vid.read()
prevHash= imagehash.dhash(Image.fromarray(np.uint8(prevImg)).convert('RGB'), hash_size=64)
while success:
i= 0
currImg= None
while i<FRAMES_SKIP and success:
success, currImg= vid.read()
i+=1
if not success:
print('Video END or Video File corrupted.')
break
currHash= imagehash.dhash(Image.fromarray(np.uint8(currImg)).convert('RGB'), hash_size=64)
f.write(str(currHash-prevHash)+' '+str(vid.get(cv2.CAP_PROP_POS_FRAMES))+'\n')
prevHash= currHash
f.close()
vid.release()
if __name__ == '__main__':
videoPath= input('Enter absolute path of video file with / as separator\n')
frameSkip= int(input('Number of frames to skip in between slides\n'))
videoAnalysis(frameSkip, videoPath)