-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
executable file
·30 lines (24 loc) · 1.28 KB
/
utils.py
File metadata and controls
executable file
·30 lines (24 loc) · 1.28 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
#coding=utf-8
import os
import cv2
import numpy as np
# -- IO utils
def read_txt_lines(filepath):
assert os.path.isfile( filepath ), "Error when trying to read txt file, path does not exist: {}".format(filepath)
with open( filepath ) as myfile:
content = myfile.read().splitlines()
return content
def save2npz(filename, data=None):
assert data is not None, "data is {}".format(data)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
np.savez_compressed(filename, data=data)
def read_video(filename):
cap = cv2.VideoCapture(filename)
while(cap.isOpened()):
ret, frame = cap.read() # BGR
if ret:
yield frame
else:
break
cap.release()