-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest4.py
51 lines (41 loc) · 1.29 KB
/
test4.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
50
import cv2
import numpy
import numpy as np
import os
import ffmpeg
import subprocess
# Extracting a dataframe for every second
command = "ffmpeg -i TrimmedVideo.mp4 -vf fps=1 frames/frame%04d.jpg -hide_banner"
subprocess.call(command, shell=True)
path, dirs, files = next(os.walk("./frames"))
file_count = len(files)
print(file_count)
i = "0001"
while int(i)<file_count :
img1 = cv2.imread('thumb0135.jpg',0)
# print('frames/frame'+ i +'.jpg')
# getting the difference of the images
img2 = cv2.imread('frames/frame' + i + '.jpg', 0)
res = cv2.absdiff(img1, img2)
res = res.astype(np.uint8)
percentage = (numpy.count_nonzero(res) * 100) / res.size
print(percentage)
if percentage < 1:
print('match found : frames/frame' + i + '.jpg')
break
else:
print(i)
i = str(int(i)+1)
while len(i) < 4:
i = '0' + i
print(i)
# img1 = cv2.imread('thumb0135.jpg', 0)
# img2 = cv2.imread('frames/frame0143.jpg', 0)
#--- take the absolute difference of the images ---
# res = cv2.absdiff(img1, img2)
#--- convert the result to integer type ---
# res = res.astype(np.uint8)
#--- find percentage difference based on number of pixels that are not zero ---
# percentage = (numpy.count_nonzero(res) * 100)/ res.size
#
# print(percentage)