-
Notifications
You must be signed in to change notification settings - Fork 2
/
target2-p4.py
67 lines (52 loc) · 1.46 KB
/
target2-p4.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import cv2 as cv
import numpy as np
import time
def rescale(frame,scale=0.75):
width=int(frame.shape[1]*scale)
height=int(frame.shape[0]*scale)
dimension=(width,height)
return cv.resize(frame,dimension,interpolation=cv.INTER_AREA)
def finderr(dif):
err=np.sum(dif**2)
mse=err/(float)(dif.shape[1] * dif.shape[0])
return mse
vidfilename="Seoul - 21985.mp4"
count =0
filename="IMG"
filecount=1
path="extract"
scale=float(input("Enter the rescale multiplier\n"))
frameskip=(int)(input("Enter how many frames to skip after each pick\n"))
frameskip+=1
capture = cv.VideoCapture(vidfilename)
error=0
length=int(capture.get(cv.CAP_PROP_FRAME_COUNT))
print(length)
errorcount=0.0
while(True):
isTrue, frame=capture.read()
count+=1
if(isTrue==False):
break
if(count%frameskip==0):
frame=rescale(frame,scale)
if(count==frameskip):
prevframe=frame
filename=path+"\\IMG"+str(filecount)+".png"
filecount+=1
prevgray=cv.cvtColor(prevframe,cv.COLOR_BGR2GRAY)
gray=cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
dif=cv.subtract(prevgray,gray)
error=finderr(dif)
prevframe=frame
if( cv.waitKey(25) & 0xFF==ord('d')):
break;
#errorcount+=error
if(error==0):
cv.imwrite(filename,frame)
#print(errorcount)
#errorcount=float(errorcount/filecount)
#print(errorcount)
capture.release()
cv.destroyAllWindows()
cv.waitKey(0)