-
Notifications
You must be signed in to change notification settings - Fork 0
/
cap_frame_@_time.py
59 lines (46 loc) · 1.3 KB
/
cap_frame_@_time.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 26 11:14:27 2018
@author: kamran
"""
'''
Using OpenCV takes a mp4 video and produces a number of images.
Requirements
----
You require OpenCV 3.2 to be installed.
Run
----
Open the main.py and edit the path to the video. Then run:
$ python main.py
Which will produce a folder called data with the images. There will be 2000+ images for example.mp4.
'''
import cv2
#import numpy as np
import os
#CHange the Directory
os.chdir("/home/kamran/Deep Learning/Videos/Script")
# Playing video from file:
vid_cap = cv2.VideoCapture('trump.mp4')
# To get the frame rate of the Video
framerate = vid_cap.get(5)
try:
if not os.path.exists('data'):
os.makedirs('data')
except OSError:
print ('Error: Creating directory of data')
currentFrame = 0
ret = True
vid_cap.set(cv2.CAP_PROP_POS_MSEC,20000) # just capture to 20 sec. position
while(ret):
# Capture frame-by-frame
ret, frame = vid_cap.read()
# Saves image of the current frame in jpg file
name = './data/frame' + str(currentFrame) + '.jpg'
#print ('Creating...' + name)
cv2.imwrite(name, frame) # Saves the frame as an image
# To stop duplicate images
currentFrame += 1
# When everything done, release the capture
vid_cap.release()
cv2.destroyAllWindows()