nesting: Grew fix to fix tensor displaying. Added list handling. Improved tensor display test. Added list editing handling.

This commit is contained in:
SimLeek
2019-02-20 22:45:12 -07:00
parent 4cadbe5c7d
commit ef467f2b61
4 changed files with 21 additions and 11 deletions

View File

@ -1 +1 @@
__version__ = '0.4.0'
__version__ = '0.4.1'

View File

@ -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()

View File

@ -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):

View File

@ -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()
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()