-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframeRead.py
More file actions
49 lines (38 loc) · 1.27 KB
/
frameRead.py
File metadata and controls
49 lines (38 loc) · 1.27 KB
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 os
import time
myPath='imgs' # file name where the frames will be saved
frameNum=50 #increase or decrease value to store less or more frames per second
minBlur=500
grayImage=False
saveData=True
showImage=True
count=0
countSave=0
global countFolder
#Path of the video file
cap=cv2.VideoCapture('50m_100m_9ths_0p5kts_0p4m_0deg_002_c_overhead.mkv')
def saveDataFunc():
global countFolder
countFolder=0
while os.path.exists(myPath+str(countFolder)):
countFolder=countFolder+1
os.makedirs(myPath+str(countFolder))
if saveData:saveDataFunc()
while True:
success, img=cap.read()
img= cv2.resize(img, None, fx=0.2, fy=0.2, interpolation=cv2.INTER_AREA)
if grayImage: img=cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
if saveData:
blur=cv2.Laplacian(img, cv2.CV_64F).var()
if count % frameNum==0 and blur>minBlur:
nowTime=time.time()
cv2.imwrite(myPath + str(countFolder)+ '/' + str(countSave) + "_" + str(int(blur)) + " " + str(nowTime) + ".png", img )
countSave += 1
count += 1
if showImage:
cv2.imshow("Image", img)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
cap.release()
cv2.destroyAllWindows()