diff --git a/cvpubsubs/__init__.py b/cvpubsubs/__init__.py index abeeedb..f0ede3d 100644 --- a/cvpubsubs/__init__.py +++ b/cvpubsubs/__init__.py @@ -1 +1 @@ -__version__ = '0.4.0' +__version__ = '0.4.1' diff --git a/cvpubsubs/webcam_pub/frame_handler.py b/cvpubsubs/webcam_pub/frame_handler.py index 87a61c6..2eb1372 100644 --- a/cvpubsubs/webcam_pub/frame_handler.py +++ b/cvpubsubs/webcam_pub/frame_handler.py @@ -73,7 +73,9 @@ class VideoHandlerThread(threading.Thread): if frame is not None: frame = frame for c in self.callbacks: - frame = c(frame, self.cam_id) + frame_c = c(frame, self.cam_id) + if frame_c is not None: + frame = frame_c msg_owner = sub_owner.get() sub_owner.release() sub_cam.release() diff --git a/cvpubsubs/window_sub/cv_window_sub.py b/cvpubsubs/window_sub/cv_window_sub.py index 5bd9c03..da1533e 100644 --- a/cvpubsubs/window_sub/cv_window_sub.py +++ b/cvpubsubs/window_sub/cv_window_sub.py @@ -69,25 +69,26 @@ class SubscriberWindows(object): def _display_frames(self, frames, win_num): for f in range(len(frames)): - if frames[f].dtype.num == 17 or len(frames[f].shape) > 3: # detect nested - self._display_frames(frames[f], win_num) + # detect nested: + if isinstance(frames[f], (list, tuple)) or frames[f].dtype.num == 17 or len(frames[f].shape) > 3: + win_num = self._display_frames(frames[f], win_num) else: cv2.imshow(self.window_names[win_num % len(self.window_names)] + " (press ESC to quit)", frames[f]) win_num += 1 + return win_num def update_window_frames(self): win_num = 0 for i in range(len(self.input_vid_global_names)): - if self.input_vid_global_names[i] in self.frame_dict and not isinstance(self.frame_dict[ - self.input_vid_global_names[i]], - NoData): + if self.input_vid_global_names[i] in self.frame_dict and \ + not isinstance(self.frame_dict[self.input_vid_global_names[i]], NoData): if len(self.callbacks) > 0 and self.callbacks[i % len(self.callbacks)] is not None: frames = self.callbacks[i % len(self.callbacks)](self.frame_dict[self.input_vid_global_names[i]]) else: frames = self.frame_dict[self.input_vid_global_names[i]] if isinstance(frames, np.ndarray) and len(frames.shape) <= 3: frames = [frames] - self._display_frames(frames, win_num) + win_num = self._display_frames(frames, win_num) # todo: figure out how to get the red x button to work. Try: https://stackoverflow.com/a/37881722/782170 def loop(self): diff --git a/tests/test_sub_win.py b/tests/test_sub_win.py index 594740c..7adf8a4 100644 --- a/tests/test_sub_win.py +++ b/tests/test_sub_win.py @@ -18,7 +18,7 @@ def print_keys_thread(): msg_cmd = '' while msg_cmd != 'quit': key_chr = sub_key.get(sub_key) # type: np.ndarray - WinCtrl.key_pub.publish(None) # consume data + WinCtrl.key_pub.publish(None) # consume data if key_chr is not None: print("key pressed: " + str(key_chr)) msg_cmd = sub_cmd.get() @@ -92,7 +92,14 @@ class TestSubWin(ut.TestCase): def test_nested_frames(self): def nest_frame(frame, cam_id): - frame = np.asarray([[[[[[frame]]]]]]) + frame = np.asarray([[[[[[frame]]]]], [[[[[frame]]], [[[frame]]]]]]) return frame - w.VideoHandlerThread(callbacks=[nest_frame] + w.display_callbacks).display() \ No newline at end of file + v = w.VideoHandlerThread(callbacks=[nest_frame] + w.display_callbacks) + v.start() + + SubscriberWindows(window_names=[str(i) for i in range(3)], + video_sources=[str(0)] + ).loop() + + v.join()