From 494acd468eb42370546b84fcecdae6dfa89f37f4 Mon Sep 17 00:00:00 2001 From: SimLeek Date: Thu, 18 Jan 2018 16:57:40 -0700 Subject: [PATCH] updated cv_pubsubs to handle multiple output windows. Combined all RGC filters into one file. Added whole image color averaging. --- cv_webcam_pub.py | 6 +++++- cv_window_sub.py | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cv_webcam_pub.py b/cv_webcam_pub.py index 244b903..9a6cf33 100644 --- a/cv_webcam_pub.py +++ b/cv_webcam_pub.py @@ -18,6 +18,7 @@ def get_open_cv_cam_ids(): # type: () -> List[cv2.VideoCapture] cam_list.append(len(cam_list)) return cam_list +import time def pub_cv_cam_thread(camId, # type: Union[int, str] requestSize=(1280, 720) # type: Tuple[int, int] @@ -30,7 +31,10 @@ def pub_cv_cam_thread(camId, # type: Union[int, str] if not cam.isOpened(): pubsub.publish("cvcams." + str(camId) + ".status", "failed") return False + now = time.time() while ( msg != 'q'): + time.sleep(1./(60-(time.time()-now))) + now = time.time() (ret, frame) = cam.read() # type: Tuple[bool, np.ndarray ] if ret is False or not isinstance(frame, np.ndarray): cam.release() @@ -77,7 +81,7 @@ def cv_cam_pub_handler(camId, # type: Union[int, str] frame = frame[0] frameHandler(frame, camId) msgOwner = listenFixed(subOwner, block=False, empty='') - pubsub.publish("cvcams.0.cmd", 'q') + pubsub.publish("cvcams."+str(camId)+".cmd", 'q') t.join() def init_cv_cam_pub_handler(camId, # type: Union[int, str] diff --git a/cv_window_sub.py b/cv_window_sub.py index 97cc4eb..c7d9315 100644 --- a/cv_window_sub.py +++ b/cv_window_sub.py @@ -5,30 +5,41 @@ if False: cvWindows = [] frameDict={} - +import time def cv_win_sub(*, names, # type: List[str] inputVidGlobalNames, # type: List[str] callbacks=(None,) ): global cvWindows - for name in names: - cvWindows.append(name) - cv2.namedWindow(name) global frameDict + firstRun=True + timeMod = None while True: + t = int(time.time()) * 1000 + if firstRun: + timeMod = t % 1000 + firstRun = False #global camImg for i in range(len(inputVidGlobalNames)): if inputVidGlobalNames[i] in frameDict and frameDict[inputVidGlobalNames[i]] is not None: if callbacks[i%len(callbacks)] is not None: - frame = callbacks[i%len(callbacks)](frameDict[inputVidGlobalNames[i]]) + frames = callbacks[i%len(callbacks)](frameDict[inputVidGlobalNames[i]]) else: - frame = frameDict[inputVidGlobalNames[i]] - cv2.imshow(names[i%len(names)], frame) + frames = frameDict[inputVidGlobalNames[i]] + for i in range(len(frames)): + if t % 1000 == timeMod: + if names[i%len(names)]+str(i) not in cvWindows: + cvWindows.append(names[i%len(names)]+str(i)) + cv2.namedWindow(names[i%len(names)]+str(i)) + cv2.imshow(names[i%len(names)]+str(i), frames[i]) if cv2.waitKey(1)& 0xFF==ord('q'): - for name in names: + for name in cvWindows: cv2.destroyWindow(name) + for n in names: + pubsub.publish("cvcamhandlers." + str(n) + ".cmd", "q") + return