-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.py
43 lines (27 loc) · 930 Bytes
/
utils.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
import glob
import cv2 as cv
def getfiles(path):
print('searching', path)
files = sorted(glob.glob(path+'/*.png'))
if not files:
raise FileNotFoundError(f'no files found under {path}')
return files
def visualize_image_on_colab(image_path):
from google.colab.patches import cv2_imshow
files = getfiles(image_path)
if not files:
raise FileNotFoundError(f'No files found under {image_path}')
for fn in files:
image = cv.imread(fn)
cv2_imshow(image) # Note cv2_imshow, not cv2.imshow
def visualize_video_on_colab(video_path):
from google.colab.patches import cv2_imshow
cap = cv.VideoCapture(video_path)
while cap.isOpened():
ret, image = cap.read()
if not ret:
break
cv2_imshow(image) # Note cv2_imshow, not cv2.imshow
cv.waitKey(1) & 0xff
cv.destroyAllWindows()
cap.release()