forked from kcct-fujimotolab/3DCNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoto3d.py
37 lines (27 loc) · 1.01 KB
/
videoto3d.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
import numpy as np
import cv2
class Videoto3D:
def __init__(self, width, height, depth):
self.width = width
self.height = height
self.depth = depth
def video3d(self, filename, color=False, skip=True):
cap = cv2.VideoCapture(filename)
nframe = cap.get(cv2.CAP_PROP_FRAME_COUNT)
if skip:
frames = [x * nframe / self.depth for x in range(self.depth)]
else:
frames = [x for x in range(self.depth)]
framearray = []
for i in range(self.depth):
cap.set(cv2.CAP_PROP_POS_FRAMES, frames[i])
ret, frame = cap.read()
frame = cv2.resize(frame, (self.height, self.width))
if color:
framearray.append(frame)
else:
framearray.append(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY))
cap.release()
return np.array(framearray)
def get_UCF_classname(self, filename):
return filename[filename.find('_') + 1:filename.find('_', 2)]