-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo_capture.py
60 lines (44 loc) · 1.51 KB
/
video_capture.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
60
# based on https://github.com/nrsyed/computer-vision/tree/master/multithread
import cv2
import os
from datetime import datetime
from VideoGet import VideoGet
from VideoShow import VideoShow
lst_video_getter = []
lst_video_shower = []
# list the ip cams you want to access, and assign a name for each one
lst_ip_cam = [0, # webcam
"http://root:[email protected]/mjpg/video.mjpg",
"rtsp://192.168.0.13:554/ch0"]
lst_cam_name = ["cam1","cam2","cam3"]
dataset_folder = "dataset"
if not os.path.exists(dataset_folder):
os.makedirs(dataset_folder)
for i in range(len(lst_ip_cam)):
if not os.path.exists(dataset_folder+"/"+lst_cam_name[i]):
os.makedirs(dataset_folder+"/"+lst_cam_name[i])
video_getter = VideoGet(lst_ip_cam[i]).start()
lst_video_getter.append(video_getter)
lst_video_shower.append(VideoShow(video_getter.frame,lst_cam_name[i]).start())
stop = False
snap = False
while True:
for i in range(len(lst_video_getter)):
if lst_video_getter[i].stopped or lst_video_shower[i].stopped:
lst_video_shower[i].stop()
lst_video_getter[i].stop()
stop=True
if lst_video_shower[i].snap:
snap = True
frame = lst_video_getter[i].frame
lst_video_shower[i].frame = frame
if snap:
for i in range(len(lst_video_getter)):
lst_video_shower[i].safe_snap()
lst_video_shower[i].snap=False
snap=False
if stop:
for i in range(len(lst_video_getter)):
lst_video_shower[i].stop()
lst_video_getter[i].stop()
break