-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathframefetch.py
52 lines (33 loc) · 829 Bytes
/
framefetch.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
#!/usr/bin/python
import cv2
import numpy as np
import sys
width=1280.
height=720.
hJust=910
""" global vars """
if len(sys.argv) < 5:
print("dir outdir vidnr hypighet")
exit()
vidnr=sys.argv[3]
videofile=sys.argv[1]+vidnr+".mp4" # =0 if webcam
outfile=sys.argv[2]
hypighet=int(sys.argv[4])
imgnr=0
save=0
cap = cv2.VideoCapture(videofile)
while not cap.isOpened():
cap = cv2.VideoCapture(videofile)
cv2.waitKey(1000)
print("awaiting video...")
while(1):
# Take each frame
ok, frame = cap.read()
if (not ok):
print("videofil slutt")
break
if(imgnr % hypighet == 0):
cv2.imwrite("%s%s_%s.jpg"%(outfile,vidnr,imgnr),frame,[cv2.IMWRITE_JPEG_QUALITY ,95])
print("%s%s_%s.jpg saved"%(outfile,vidnr,imgnr))
imgnr+=1
cv2.waitKey(10)