11"""Publish frames so any function within this program can find them."""
22
3+ import asyncio
4+ import sys
35import threading
46import time
5- import asyncio
6- import cv2
77import warnings
8- import sys
8+
9+ import cv2
910
1011using_pyv4l2cam = False
1112try :
@@ -123,6 +124,7 @@ def pub_cam_loop_opencv(
123124 request_size : Tuple [int , int ] = (- 1 , - 1 ),
124125 high_speed : bool = True ,
125126 fps_limit : float = float ("inf" ),
127+ extra : Optional [List [Tuple [int , int ]]] = None ,
126128) -> bool :
127129 """
128130 Publish whichever camera you select to CVCams.<cam_id>.Vid.
@@ -186,6 +188,9 @@ def pub_cam_loop_opencv(
186188 return True
187189
188190
191+ uid_dict : Dict [str , threading .Thread ] = {}
192+
193+
189194def pub_cam_thread (
190195 cam_id : Union [int , str ],
191196 request_ize : Tuple [int , int ] = (- 1 , - 1 ),
@@ -194,22 +199,27 @@ def pub_cam_thread(
194199) -> threading .Thread :
195200 """Run pub_cam_loop in a new thread. Starts on creation."""
196201
197- if (
198- sys .platform == "linux"
199- and using_pyv4l2cam
200- and (
201- isinstance (cam_id , int )
202- or (isinstance (cam_id , str ) and "/dev/video" in cam_id )
203- )
204- ):
205- pub_cam_loop = pub_cam_loop_pyv4l2
202+ name = uid_for_source (cam_id )
203+ if name in uid_dict .keys ():
204+ t = uid_dict [name ]
206205 else :
207- pub_cam_loop = pub_cam_loop_opencv
206+ if (
207+ sys .platform == "linux"
208+ and using_pyv4l2cam
209+ and (
210+ isinstance (cam_id , int )
211+ or (isinstance (cam_id , str ) and "/dev/video" in cam_id )
212+ )
213+ ):
214+ pub_cam_loop = pub_cam_loop_pyv4l2
215+ else :
216+ pub_cam_loop = pub_cam_loop_opencv
208217
209- t = threading .Thread (
210- target = pub_cam_loop , args = (cam_id , request_ize , high_speed , fps_limit )
211- )
212- t .start ()
218+ t = threading .Thread (
219+ target = pub_cam_loop , args = (cam_id , request_ize , high_speed , fps_limit )
220+ )
221+ uid_dict [name ] = t
222+ t .start ()
213223 return t
214224
215225
0 commit comments