Merge pull request #14 from SimLeek/nesting
nesting: Grew fix to fix tensor displaying. Added list handling. Impr…
This commit is contained in:
@ -1 +1 @@
|
|||||||
__version__ = '0.4.0'
|
__version__ = '0.4.1'
|
||||||
|
@ -73,7 +73,9 @@ class VideoHandlerThread(threading.Thread):
|
|||||||
if frame is not None:
|
if frame is not None:
|
||||||
frame = frame
|
frame = frame
|
||||||
for c in self.callbacks:
|
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()
|
msg_owner = sub_owner.get()
|
||||||
sub_owner.release()
|
sub_owner.release()
|
||||||
sub_cam.release()
|
sub_cam.release()
|
||||||
|
@ -69,25 +69,26 @@ class SubscriberWindows(object):
|
|||||||
|
|
||||||
def _display_frames(self, frames, win_num):
|
def _display_frames(self, frames, win_num):
|
||||||
for f in range(len(frames)):
|
for f in range(len(frames)):
|
||||||
if frames[f].dtype.num == 17 or len(frames[f].shape) > 3: # detect nested
|
# detect nested:
|
||||||
self._display_frames(frames[f], win_num)
|
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:
|
else:
|
||||||
cv2.imshow(self.window_names[win_num % len(self.window_names)] + " (press ESC to quit)", frames[f])
|
cv2.imshow(self.window_names[win_num % len(self.window_names)] + " (press ESC to quit)", frames[f])
|
||||||
win_num += 1
|
win_num += 1
|
||||||
|
return win_num
|
||||||
|
|
||||||
def update_window_frames(self):
|
def update_window_frames(self):
|
||||||
win_num = 0
|
win_num = 0
|
||||||
for i in range(len(self.input_vid_global_names)):
|
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[
|
if self.input_vid_global_names[i] in self.frame_dict and \
|
||||||
self.input_vid_global_names[i]],
|
not isinstance(self.frame_dict[self.input_vid_global_names[i]], NoData):
|
||||||
NoData):
|
|
||||||
if len(self.callbacks) > 0 and self.callbacks[i % len(self.callbacks)] is not None:
|
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]])
|
frames = self.callbacks[i % len(self.callbacks)](self.frame_dict[self.input_vid_global_names[i]])
|
||||||
else:
|
else:
|
||||||
frames = self.frame_dict[self.input_vid_global_names[i]]
|
frames = self.frame_dict[self.input_vid_global_names[i]]
|
||||||
if isinstance(frames, np.ndarray) and len(frames.shape) <= 3:
|
if isinstance(frames, np.ndarray) and len(frames.shape) <= 3:
|
||||||
frames = [frames]
|
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
|
# todo: figure out how to get the red x button to work. Try: https://stackoverflow.com/a/37881722/782170
|
||||||
def loop(self):
|
def loop(self):
|
||||||
|
@ -18,7 +18,7 @@ def print_keys_thread():
|
|||||||
msg_cmd = ''
|
msg_cmd = ''
|
||||||
while msg_cmd != 'quit':
|
while msg_cmd != 'quit':
|
||||||
key_chr = sub_key.get(sub_key) # type: np.ndarray
|
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:
|
if key_chr is not None:
|
||||||
print("key pressed: " + str(key_chr))
|
print("key pressed: " + str(key_chr))
|
||||||
msg_cmd = sub_cmd.get()
|
msg_cmd = sub_cmd.get()
|
||||||
@ -92,7 +92,14 @@ class TestSubWin(ut.TestCase):
|
|||||||
|
|
||||||
def test_nested_frames(self):
|
def test_nested_frames(self):
|
||||||
def nest_frame(frame, cam_id):
|
def nest_frame(frame, cam_id):
|
||||||
frame = np.asarray([[[[[[frame]]]]]])
|
frame = np.asarray([[[[[[frame]]]]], [[[[[frame]]], [[[frame]]]]]])
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
w.VideoHandlerThread(callbacks=[nest_frame] + w.display_callbacks).display()
|
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()
|
||||||
|
Reference in New Issue
Block a user