diff --git a/.gitignore b/.gitignore index 8f7fbc5..fb24077 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,4 @@ venv.bak/ .idea/ .pytest_cache/ +.coveragerc diff --git a/displayarray/__init__.py b/displayarray/__init__.py index 90a7bca..277b1e9 100644 --- a/displayarray/__init__.py +++ b/displayarray/__init__.py @@ -4,9 +4,8 @@ Display any array, webcam, or video file. display is a function that displays these in their own windows. """ -__version__ = "0.7.2" +__version__ = "0.7.3" -from .window.subscriber_windows import display, breakpoint_display -from .frame.frame_updater import read_updates +from .window.subscriber_windows import display, breakpoint_display, read_updates from .frame.frame_publishing import publish_updates_zero_mq, publish_updates_ros from . import effects diff --git a/displayarray/frame/__init__.py b/displayarray/frame/__init__.py index 451ab23..5a14093 100644 --- a/displayarray/frame/__init__.py +++ b/displayarray/frame/__init__.py @@ -9,7 +9,7 @@ np_cam simulates numpy arrays as OpenCV cameras """ from . import subscriber_dictionary -from .frame_updater import FrameUpdater, read_updates +from .frame_updater import FrameUpdater from .get_frame_ids import get_cam_ids from .np_to_opencv import NpCam from .frame_publishing import pub_cam_thread diff --git a/displayarray/frame/frame_publishing.py b/displayarray/frame/frame_publishing.py index cbb5ba9..5e4ad68 100644 --- a/displayarray/frame/frame_publishing.py +++ b/displayarray/frame/frame_publishing.py @@ -20,7 +20,7 @@ def pub_cam_loop( cam_id: Union[int, str, np.ndarray], request_size: Tuple[int, int] = (-1, -1), high_speed: bool = True, - fps_limit: float = 240, + fps_limit: float = float("inf"), ) -> bool: """ Publish whichever camera you select to CVCams..Vid. @@ -47,7 +47,6 @@ def pub_cam_loop( subscriber_dictionary.register_cam(name) - # cam.set(cv2.CAP_PROP_CONVERT_RGB, 0) frame_counter = 0 sub = subscriber_dictionary.cam_cmd_sub(name) @@ -89,7 +88,7 @@ def pub_cam_thread( cam_id: Union[int, str], request_ize: Tuple[int, int] = (-1, -1), high_speed: bool = True, - fps_limit: float = 240, + fps_limit: float = float("inf"), ) -> threading.Thread: """Run pub_cam_loop in a new thread. Starts on creation.""" t = threading.Thread( @@ -186,8 +185,8 @@ async def publish_updates_ros( }[dtype] else: msg_type = ( - dtype - ) # allow users to use their own custom messages in numpy arrays + dtype # allow users to use their own custom messages in numpy arrays + ) return msg_type publishers: Dict[str, rospy.Publisher] = {} diff --git a/displayarray/frame/frame_updater.py b/displayarray/frame/frame_updater.py index de14e01..52aa0a8 100644 --- a/displayarray/frame/frame_updater.py +++ b/displayarray/frame/frame_updater.py @@ -26,7 +26,7 @@ class FrameUpdater(threading.Thread): callbacks: Optional[Union[List[FrameCallable], FrameCallable]] = None, request_size: Tuple[int, int] = (-1, -1), high_speed: bool = True, - fps_limit: float = 240, + fps_limit: float = float("inf"), ): """Create the frame updater thread.""" super(FrameUpdater, self).__init__(target=self.loop, args=()) @@ -115,7 +115,7 @@ class FrameUpdater(threading.Thread): raise self.exception_raised -async def read_updates( +'''async def read_updates( *vids, callbacks: Optional[ Union[ @@ -132,14 +132,14 @@ async def read_updates( """ Read back all updates from the requested videos. - Example usage: + Examp#le usage: - .. code-block:: python + .. co#de-block:: python - >>> from examples.videos import test_video - >>> f = 0 - >>> for f, r in enumerate(read_updates(test_video, end_callback=lambda :f==2)): - ... print(f"Frame:{f}. Array:{r}") + >>#> from examples.videos import test_video + >>#> f = 0 + >>#> for f, r in enumerate(read_updates(test_video, end_callback=lambda :f==2)): + ..#. print(f"Frame:{f}. Array:{r}") """ from displayarray.window import SubscriberWindows @@ -174,7 +174,7 @@ async def read_updates( for v in vid_names: subscriber_dictionary.stop_cam(v) for v in vid_threads: - v.join() + v.join()''' async def read_updates_zero_mq( diff --git a/displayarray/window/subscriber_windows.py b/displayarray/window/subscriber_windows.py index d054b2d..89c9504 100644 --- a/displayarray/window/subscriber_windows.py +++ b/displayarray/window/subscriber_windows.py @@ -30,6 +30,7 @@ class SubscriberWindows(object): window_names: Iterable[str] = ("displayarray",), video_sources: Iterable[Union[str, int]] = (0,), callbacks: Optional[List[Callable[[np.ndarray], Any]]] = None, + silent: bool = False, ): """Create the array displaying window.""" self.source_names: List[Union[str, int]] = [] @@ -39,14 +40,16 @@ class SubscriberWindows(object): self.window_names: List[str] = [] self.input_cams: List[str] = [] self.exited = False + self.silent = silent if callbacks is None: callbacks = [] for name in video_sources: self.add_source(name) self.callbacks = callbacks - for name in window_names: - self.add_window(name) + if not self.silent: + for name in window_names: + self.add_window(name) self.update() @@ -54,6 +57,11 @@ class SubscriberWindows(object): self.update() return not self.exited + def __iter__(self): + while not self.exited: + self.update() + yield self.frames + def block(self): """Update the window continuously while blocking the outer program.""" self.loop() @@ -109,7 +117,8 @@ class SubscriberWindows(object): mousey = MouseEvent(event, x, y, flags, param) window_commands.mouse_pub.publish(mousey) - def _display_frames(self, frames, win_num=0, ids=None): + def display_frames(self, frames, win_num=0, ids=None): + """Display a list of frames on multiple windows.""" if isinstance(frames, Exception): raise frames for f in range(len(frames)): @@ -122,7 +131,7 @@ class SubscriberWindows(object): and (len(frames[f].shape) != 3 or frames[f].shape[-1] != 3) ) ): - win_num = self._display_frames(frames[f], win_num, ids) + win_num = self.display_frames(frames[f], win_num, ids) else: if len(self.window_names) <= win_num: self.add_window(str(win_num)) @@ -157,7 +166,7 @@ class SubscriberWindows(object): self.frames[fr] = self.callbacks[-1](self.frames[fr]) break - def update_window_frames(self): + def update_frames(self): """Update the windows with the newest data for all frames.""" self.frames = [] for i in range(len(self.input_vid_global_names)): @@ -172,9 +181,11 @@ class SubscriberWindows(object): frame = c(self.frames[-1]) if frame is not None: self.frames[-1] = frame - self.__check_too_many_channels() + if not self.silent: + self.__check_too_many_channels() self.FRAME_DICT[self.input_vid_global_names[i]] = NoData() - self._display_frames(self.frames) + if not self.silent: + self.display_frames(self.frames) def update(self, arr: np.ndarray = None, id: str = None): """Update window frames once. Optionally add a new input and input id.""" @@ -182,9 +193,10 @@ class SubscriberWindows(object): global_cv_display_callback(arr, id) if id not in self.input_cams: self.add_source(id) - self.add_window(id) + if not self.silent: + self.add_window(id) sub_cmd = window_commands.win_cmd_sub() - self.update_window_frames() + self.update_frames() msg_cmd = sub_cmd.get() key = self.handle_keys(cv2.waitKey(1)) return msg_cmd, key @@ -231,7 +243,7 @@ class SubscriberWindows(object): def _get_video_callback_dict_threads( *vids, callbacks: Optional[Dict[Any, Union[FrameCallable, List[FrameCallable]]]] = None, - fps=240, + fps=float("inf"), size=(-1, -1), ): assert callbacks is not None @@ -264,7 +276,7 @@ def _get_video_threads( FrameCallable, ] ] = None, - fps=240, + fps=float("inf"), size=(-1, -1), ): vid_threads: List[Thread] = [] @@ -300,8 +312,9 @@ def display( ] = None, window_names=None, blocking=False, - fps_limit=240, + fps_limit=float("inf"), size=(-1, -1), + silent=False, ): """ Display all the arrays, cameras, and videos passed in. @@ -318,11 +331,15 @@ def display( if window_names is None: window_names = ["window {}".format(i) for i in range(len(vids))] if blocking: - SubscriberWindows(window_names=window_names, video_sources=vids).loop() + SubscriberWindows( + window_names=window_names, video_sources=vids, silent=silent + ).loop() for vt in vid_threads: vt.join() else: - s = SubscriberWindows(window_names=window_names, video_sources=vids) + s = SubscriberWindows( + window_names=window_names, video_sources=vids, silent=silent + ) s.close_threads = vid_threads return s @@ -330,3 +347,8 @@ def display( def breakpoint_display(*args, **kwargs): """Display all the arrays, cameras, and videos passed in. Stops code execution until the window is closed.""" return display(*args, **kwargs, blocking=True) + + +def read_updates(*args, **kwargs): + """Read back all frame updates and yield a list of frames. List is empty if no frames were read.""" + return display(*args, **kwargs, silent=True) diff --git a/docs/.doctrees/display.doctree b/docs/.doctrees/display.doctree index 023d9ae..e89bb89 100644 Binary files a/docs/.doctrees/display.doctree and b/docs/.doctrees/display.doctree differ diff --git a/docs/.doctrees/environment.pickle b/docs/.doctrees/environment.pickle index 55e2066..9fcb3ec 100644 Binary files a/docs/.doctrees/environment.pickle and b/docs/.doctrees/environment.pickle differ diff --git a/docs/.doctrees/frame.doctree b/docs/.doctrees/frame.doctree index d1f789d..b14a6c3 100644 Binary files a/docs/.doctrees/frame.doctree and b/docs/.doctrees/frame.doctree differ diff --git a/docs/_modules/displayarray/__main__/index.html b/docs/_modules/displayarray/__main__/index.html index 0dd93d9..733665e 100644 --- a/docs/_modules/displayarray/__main__/index.html +++ b/docs/_modules/displayarray/__main__/index.html @@ -173,7 +173,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/displayarray/effects/crop/index.html b/docs/_modules/displayarray/effects/crop/index.html index 3a71165..3425dfb 100644 --- a/docs/_modules/displayarray/effects/crop/index.html +++ b/docs/_modules/displayarray/effects/crop/index.html @@ -211,7 +211,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/displayarray/effects/lens/index.html b/docs/_modules/displayarray/effects/lens/index.html index 8465230..c0a7144 100644 --- a/docs/_modules/displayarray/effects/lens/index.html +++ b/docs/_modules/displayarray/effects/lens/index.html @@ -404,7 +404,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/displayarray/effects/select_channels/index.html b/docs/_modules/displayarray/effects/select_channels/index.html index ed1ce40..04dbccd 100644 --- a/docs/_modules/displayarray/effects/select_channels/index.html +++ b/docs/_modules/displayarray/effects/select_channels/index.html @@ -177,7 +177,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/displayarray/frame/frame_publishing/index.html b/docs/_modules/displayarray/frame/frame_publishing/index.html index 5945ed5..de6487f 100644 --- a/docs/_modules/displayarray/frame/frame_publishing/index.html +++ b/docs/_modules/displayarray/frame/frame_publishing/index.html @@ -53,7 +53,7 @@ cam_id: Union[int, str, np.ndarray], request_size: Tuple[int, int] = (-1, -1), high_speed: bool = True, - fps_limit: float = 240, + fps_limit: float = float("inf"), ) -> bool: """ Publish whichever camera you select to CVCams.<cam_id>.Vid. @@ -80,7 +80,6 @@ subscriber_dictionary.register_cam(name) - # cam.set(cv2.CAP_PROP_CONVERT_RGB, 0) frame_counter = 0 sub = subscriber_dictionary.cam_cmd_sub(name) @@ -122,7 +121,7 @@ cam_id: Union[int, str], request_ize: Tuple[int, int] = (-1, -1), high_speed: bool = True, - fps_limit: float = 240, + fps_limit: float = float("inf"), ) -> threading.Thread: """Run pub_cam_loop in a new thread. Starts on creation.""" t = threading.Thread( @@ -219,8 +218,8 @@ }[dtype] else: msg_type = ( - dtype - ) # allow users to use their own custom messages in numpy arrays + dtype # allow users to use their own custom messages in numpy arrays + ) return msg_type publishers: Dict[str, rospy.Publisher] = {} @@ -316,7 +315,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/displayarray/frame/frame_updater/index.html b/docs/_modules/displayarray/frame/frame_updater/index.html index 34940d7..42002dd 100644 --- a/docs/_modules/displayarray/frame/frame_updater/index.html +++ b/docs/_modules/displayarray/frame/frame_updater/index.html @@ -50,7 +50,7 @@ FrameCallable = Callable[[np.ndarray], Optional[np.ndarray]] -
[docs]class FrameUpdater(threading.Thread): +
[docs]class FrameUpdater(threading.Thread): """Thread for updating frames from a video source.""" def __init__( @@ -59,7 +59,7 @@ callbacks: Optional[Union[List[FrameCallable], FrameCallable]] = None, request_size: Tuple[int, int] = (-1, -1), high_speed: bool = True, - fps_limit: float = 240, + fps_limit: float = float("inf"), ): """Create the frame updater thread.""" super(FrameUpdater, self).__init__(target=self.loop, args=()) @@ -110,7 +110,7 @@ raise e global_cv_display_callback(frame, self.cam_id) -
[docs] def loop(self): +
[docs] def loop(self): """Continually get frames from the video publisher, run callbacks on them, and listen to commands.""" t = pub_cam_thread( self.video_source, self.request_size, self.high_speed, self.fps_limit @@ -129,7 +129,7 @@ subscriber_dictionary.stop_cam(self.cam_id) t.join()
-
[docs] def display(self, callbacks: List[Callable[[np.ndarray], Any]] = None): +
[docs] def display(self, callbacks: List[Callable[[np.ndarray], Any]] = None): """ Start default display operation. @@ -148,66 +148,66 @@ raise self.exception_raised
-
[docs]async def read_updates( - *vids, - callbacks: Optional[ - Union[ - Dict[Any, Union[FrameCallable, List[FrameCallable]]], - List[FrameCallable], - FrameCallable, - ] - ] = None, - fps_limit=float("inf"), - size=(-1, -1), - end_callback: Callable[[], bool] = lambda: False, - blocking=True, -): - """ +'''async def read_updates( + *vids, + callbacks: Optional[ + Union[ + Dict[Any, Union[FrameCallable, List[FrameCallable]]], + List[FrameCallable], + FrameCallable, + ] + ] = None, + fps_limit=float("inf"), + size=(-1, -1), + end_callback: Callable[[], bool] = lambda: False, + blocking=True, +): + """ Read back all updates from the requested videos. - Example usage: + Examp#le usage: - .. code-block:: python + .. co#de-block:: python - >>> from examples.videos import test_video - >>> f = 0 - >>> for f, r in enumerate(read_updates(test_video, end_callback=lambda :f==2)): - ... print(f"Frame:{f}. Array:{r}") + >>#> from examples.videos import test_video + >>#> f = 0 + >>#> for f, r in enumerate(read_updates(test_video, end_callback=lambda :f==2)): + ..#. print(f"Frame:{f}. Array:{r}") """ - from displayarray.window import SubscriberWindows - from displayarray.window.subscriber_windows import _get_video_threads + from displayarray.window import SubscriberWindows + from displayarray.window.subscriber_windows import _get_video_threads - vid_names = [uid_for_source(name) for name in vids] - vid_threads = _get_video_threads( - *vids, callbacks=callbacks, fps=fps_limit, size=size - ) - for v in vid_threads: - v.start() + vid_names = [uid_for_source(name) for name in vids] + vid_threads = _get_video_threads( + *vids, callbacks=callbacks, fps=fps_limit, size=size + ) + for v in vid_threads: + v.start() - while not end_callback(): - vid_update_dict = {} - dict_was_updated = False - for i in range(len(vid_names)): - if vid_names[i] in SubscriberWindows.FRAME_DICT and not isinstance( - SubscriberWindows.FRAME_DICT[vid_names[i]], NoData - ): - vid_update_dict[vid_names[i]] = SubscriberWindows.FRAME_DICT[ - vid_names[i] - ] - if ( - isinstance(vid_update_dict[vid_names[i]], np.ndarray) - and len(vid_update_dict[vid_names[i]].shape) <= 3 - ): - vid_update_dict[vid_names[i]] = [vid_update_dict[vid_names[i]]] - dict_was_updated = True - if dict_was_updated or not blocking: - yield vid_update_dict - await asyncio.sleep(0) - for v in vid_names: - subscriber_dictionary.stop_cam(v) - for v in vid_threads: - v.join()
+ while not end_callback(): + vid_update_dict = {} + dict_was_updated = False + for i in range(len(vid_names)): + if vid_names[i] in SubscriberWindows.FRAME_DICT and not isinstance( + SubscriberWindows.FRAME_DICT[vid_names[i]], NoData + ): + vid_update_dict[vid_names[i]] = SubscriberWindows.FRAME_DICT[ + vid_names[i] + ] + if ( + isinstance(vid_update_dict[vid_names[i]], np.ndarray) + and len(vid_update_dict[vid_names[i]].shape) <= 3 + ): + vid_update_dict[vid_names[i]] = [vid_update_dict[vid_names[i]]] + dict_was_updated = True + if dict_was_updated or not blocking: + yield vid_update_dict + await asyncio.sleep(0) + for v in vid_names: + subscriber_dictionary.stop_cam(v) + for v in vid_threads: + v.join()''' async def read_updates_zero_mq( @@ -404,7 +404,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12
diff --git a/docs/_modules/displayarray/frame/get_frame_ids/index.html b/docs/_modules/displayarray/frame/get_frame_ids/index.html index 88c03ca..1cb8c25 100644 --- a/docs/_modules/displayarray/frame/get_frame_ids/index.html +++ b/docs/_modules/displayarray/frame/get_frame_ids/index.html @@ -114,7 +114,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12
diff --git a/docs/_modules/displayarray/frame/np_to_opencv/index.html b/docs/_modules/displayarray/frame/np_to_opencv/index.html index 3ad2aea..cda2e37 100644 --- a/docs/_modules/displayarray/frame/np_to_opencv/index.html +++ b/docs/_modules/displayarray/frame/np_to_opencv/index.html @@ -158,7 +158,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12
diff --git a/docs/_modules/displayarray/input/index.html b/docs/_modules/displayarray/input/index.html index c6529da..fbb83ea 100644 --- a/docs/_modules/displayarray/input/index.html +++ b/docs/_modules/displayarray/input/index.html @@ -241,7 +241,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/displayarray/window/subscriber_windows/index.html b/docs/_modules/displayarray/window/subscriber_windows/index.html index 8e5f4a9..a54df67 100644 --- a/docs/_modules/displayarray/window/subscriber_windows/index.html +++ b/docs/_modules/displayarray/window/subscriber_windows/index.html @@ -63,6 +63,7 @@ window_names: Iterable[str] = ("displayarray",), video_sources: Iterable[Union[str, int]] = (0,), callbacks: Optional[List[Callable[[np.ndarray], Any]]] = None, + silent: bool = False, ): """Create the array displaying window.""" self.source_names: List[Union[str, int]] = [] @@ -72,14 +73,16 @@ self.window_names: List[str] = [] self.input_cams: List[str] = [] self.exited = False + self.silent = silent if callbacks is None: callbacks = [] for name in video_sources: self.add_source(name) self.callbacks = callbacks - for name in window_names: - self.add_window(name) + if not self.silent: + for name in window_names: + self.add_window(name) self.update() @@ -87,6 +90,11 @@ self.update() return not self.exited + def __iter__(self): + while not self.exited: + self.update() + yield self.frames +
[docs] def block(self): """Update the window continuously while blocking the outer program.""" self.loop() @@ -142,7 +150,7 @@ mousey = MouseEvent(event, x, y, flags, param) window_commands.mouse_pub.publish(mousey)
- def _display_frames(self, frames, win_num=0, ids=None): + def display_frames(self, frames, win_num=0, ids=None): if isinstance(frames, Exception): raise frames for f in range(len(frames)): @@ -155,7 +163,7 @@ and (len(frames[f].shape) != 3 or frames[f].shape[-1] != 3) ) ): - win_num = self._display_frames(frames[f], win_num, ids) + win_num = self.display_frames(frames[f], win_num, ids) else: if len(self.window_names) <= win_num: self.add_window(str(win_num)) @@ -190,7 +198,7 @@ self.frames[fr] = self.callbacks[-1](self.frames[fr]) break -
[docs] def update_window_frames(self): +
[docs] def update_frames(self): """Update the windows with the newest data for all frames.""" self.frames = [] for i in range(len(self.input_vid_global_names)): @@ -205,9 +213,11 @@ frame = c(self.frames[-1]) if frame is not None: self.frames[-1] = frame - self.__check_too_many_channels() + if not self.silent: + self.__check_too_many_channels() self.FRAME_DICT[self.input_vid_global_names[i]] = NoData() - self._display_frames(self.frames)
+ if not self.silent: + self.display_frames(self.frames)
[docs] def update(self, arr: np.ndarray = None, id: str = None): """Update window frames once. Optionally add a new input and input id.""" @@ -215,9 +225,10 @@ global_cv_display_callback(arr, id) if id not in self.input_cams: self.add_source(id) - self.add_window(id) + if not self.silent: + self.add_window(id) sub_cmd = window_commands.win_cmd_sub() - self.update_window_frames() + self.update_frames() msg_cmd = sub_cmd.get() key = self.handle_keys(cv2.waitKey(1)) return msg_cmd, key
@@ -264,7 +275,7 @@ def _get_video_callback_dict_threads( *vids, callbacks: Optional[Dict[Any, Union[FrameCallable, List[FrameCallable]]]] = None, - fps=240, + fps=float("inf"), size=(-1, -1), ): assert callbacks is not None @@ -297,7 +308,7 @@ FrameCallable, ] ] = None, - fps=240, + fps=float("inf"), size=(-1, -1), ): vid_threads: List[Thread] = [] @@ -333,8 +344,9 @@ ] = None, window_names=None, blocking=False, - fps_limit=240, + fps_limit=float("inf"), size=(-1, -1), + silent=False, ): """ Display all the arrays, cameras, and videos passed in. @@ -351,11 +363,15 @@ if window_names is None: window_names = ["window {}".format(i) for i in range(len(vids))] if blocking: - SubscriberWindows(window_names=window_names, video_sources=vids).loop() + SubscriberWindows( + window_names=window_names, video_sources=vids, silent=silent + ).loop() for vt in vid_threads: vt.join() else: - s = SubscriberWindows(window_names=window_names, video_sources=vids) + s = SubscriberWindows( + window_names=window_names, video_sources=vids, silent=silent + ) s.close_threads = vid_threads return s @@ -363,6 +379,11 @@
[docs]def breakpoint_display(*args, **kwargs): """Display all the arrays, cameras, and videos passed in. Stops code execution until the window is closed.""" return display(*args, **kwargs, blocking=True)
+ + +
[docs]def read_updates(*args, **kwargs): + """Read back all frame updates and yield a list of frames. List is empty if no frames were read.""" + return display(*args, **kwargs, silent=True)
@@ -428,7 +449,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_modules/index.html b/docs/_modules/index.html index bfd20e6..5e36bb3 100644 --- a/docs/_modules/index.html +++ b/docs/_modules/index.html @@ -104,7 +104,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 diff --git a/docs/_sources/display.rst.txt b/docs/_sources/display.rst.txt index 1a324d2..e9e6103 100644 --- a/docs/_sources/display.rst.txt +++ b/docs/_sources/display.rst.txt @@ -4,6 +4,7 @@ displayarray.display .. autofunction:: display .. autofunction:: breakpoint_display +.. autofunction:: read_updates Windows ------- diff --git a/docs/_sources/frame.rst.txt b/docs/_sources/frame.rst.txt index 8d8412f..294629a 100644 --- a/docs/_sources/frame.rst.txt +++ b/docs/_sources/frame.rst.txt @@ -1,12 +1,6 @@ displayarray.frame =================================== -Read Updates ------------- -.. currentmodule:: displayarray - -.. autofunction:: read_updates - Frame Passing ------------- .. currentmodule:: displayarray.frame @@ -19,7 +13,6 @@ Frame Passing .. autoclass:: FrameUpdater :members: -.. autofunction:: read_updates .. autofunction:: get_cam_ids .. autoclass:: NpCam diff --git a/docs/display/index.html b/docs/display/index.html index 1cc6500..46602e3 100644 --- a/docs/display/index.html +++ b/docs/display/index.html @@ -38,7 +38,7 @@

display is a function that displays these in their own windows.

-display(*vids, callbacks: Union[Dict[Any, Union[Callable[[numpy.ndarray], Optional[numpy.ndarray]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]]]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]], Callable[[numpy.ndarray], Optional[numpy.ndarray]], None] = None, window_names=None, blocking=False, fps_limit=240, size=(-1, -1))[source]
+display(*vids, callbacks: Union[Dict[Any, Union[Callable[[numpy.ndarray], Optional[numpy.ndarray]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]]]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]], Callable[[numpy.ndarray], Optional[numpy.ndarray]], None] = None, window_names=None, blocking=False, fps_limit=inf, size=(-1, -1), silent=False)[source]

Display all the arrays, cameras, and videos passed in.

callbacks can be a dictionary linking functions to videos, or a list of function or functions operating on the video

data before displaying.

@@ -53,11 +53,17 @@

Display all the arrays, cameras, and videos passed in. Stops code execution until the window is closed.

+
+
+read_updates(*args, **kwargs)[source]
+

Read back all frame updates and yield a list of frames. List is empty if no frames were read.

+
+

Windows

-class SubscriberWindows(window_names: Iterable[str] = ('displayarray',), video_sources: Iterable[Union[str, int]] = (0,), callbacks: Optional[List[Callable[[numpy.ndarray], Any]]] = None)[source]
+class SubscriberWindows(window_names: Iterable[str] = ('displayarray',), video_sources: Iterable[Union[str, int]] = (0,), callbacks: Optional[List[Callable[[numpy.ndarray], Any]]] = None, silent: bool = False)[source]

Windows that subscribe to updates to cameras, videos, and arrays.

@@ -114,8 +120,8 @@
-
-update_window_frames()[source]
+
+update_frames()[source]

Update the windows with the newest data for all frames.

@@ -197,7 +203,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 | diff --git a/docs/docsrc/conf.py b/docs/docsrc/conf.py index 11561d4..bf7a52b 100644 --- a/docs/docsrc/conf.py +++ b/docs/docsrc/conf.py @@ -12,7 +12,8 @@ # import os import sys -sys.path.insert(0, os.path.abspath(f'..{os.sep}..')) + +sys.path.insert(0, os.path.abspath(f"..{os.sep}..")) # -- Project information ----------------------------------------------------- diff --git a/docs/docsrc/display.rst b/docs/docsrc/display.rst index 1a324d2..e9e6103 100644 --- a/docs/docsrc/display.rst +++ b/docs/docsrc/display.rst @@ -4,6 +4,7 @@ displayarray.display .. autofunction:: display .. autofunction:: breakpoint_display +.. autofunction:: read_updates Windows ------- diff --git a/docs/docsrc/frame.rst b/docs/docsrc/frame.rst index 8d8412f..294629a 100644 --- a/docs/docsrc/frame.rst +++ b/docs/docsrc/frame.rst @@ -1,12 +1,6 @@ displayarray.frame =================================== -Read Updates ------------- -.. currentmodule:: displayarray - -.. autofunction:: read_updates - Frame Passing ------------- .. currentmodule:: displayarray.frame @@ -19,7 +13,6 @@ Frame Passing .. autoclass:: FrameUpdater :members: -.. autofunction:: read_updates .. autofunction:: get_cam_ids .. autoclass:: NpCam diff --git a/docs/effects/index.html b/docs/effects/index.html index 9ba7bb3..fb18c18 100644 --- a/docs/effects/index.html +++ b/docs/effects/index.html @@ -273,7 +273,7 @@ Ctrl+scroll to increase/decrease channel 0.

©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 | diff --git a/docs/frame/index.html b/docs/frame/index.html index ea9a7b7..80cd0c3 100644 --- a/docs/frame/index.html +++ b/docs/frame/index.html @@ -34,22 +34,6 @@

displayarray.frame

-
-

Read Updates

-
-
-read_updates(*vids, callbacks: Union[Dict[Any, Union[Callable[[numpy.ndarray], Optional[numpy.ndarray]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]]]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]], Callable[[numpy.ndarray], Optional[numpy.ndarray]], None] = None, fps_limit=inf, size=(-1, -1), end_callback: Callable[[], bool] = <function <lambda>>, blocking=True)[source]
-

Read back all updates from the requested videos.

-

Example usage:

-
>>> from examples.videos import test_video
->>> f = 0
->>> for f, r in enumerate(read_updates(test_video, end_callback=lambda :f==2)):
-...   print(f"Frame:{f}. Array:{r}")
-
-
-
- -

Frame Passing

Handles publishing arrays, videos, and cameras.

@@ -60,7 +44,7 @@ pub_cam_thread continually publishes updates to arrays, videos, and cameras np_cam simulates numpy arrays as OpenCV cameras

-class FrameUpdater(video_source: Union[int, str, numpy.ndarray] = 0, callbacks: Union[List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]], Callable[[numpy.ndarray], Optional[numpy.ndarray]], None] = None, request_size: Tuple[int, int] = (-1, -1), high_speed: bool = True, fps_limit: float = 240)[source]
+class FrameUpdater(video_source: Union[int, str, numpy.ndarray] = 0, callbacks: Union[List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]], Callable[[numpy.ndarray], Optional[numpy.ndarray]], None] = None, request_size: Tuple[int, int] = (-1, -1), high_speed: bool = True, fps_limit: float = inf)[source]

Thread for updating frames from a video source.

@@ -82,19 +66,6 @@ np_cam simulates numpy arrays as OpenCV cameras

-
-
-read_updates(*vids, callbacks: Union[Dict[Any, Union[Callable[[numpy.ndarray], Optional[numpy.ndarray]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]]]], List[Callable[[numpy.ndarray], Optional[numpy.ndarray]]], Callable[[numpy.ndarray], Optional[numpy.ndarray]], None] = None, fps_limit=inf, size=(-1, -1), end_callback: Callable[[], bool] = <function <lambda>>, blocking=True)[source]
-

Read back all updates from the requested videos.

-

Example usage:

-
>>> from examples.videos import test_video
->>> f = 0
->>> for f, r in enumerate(read_updates(test_video, end_callback=lambda :f==2)):
-...   print(f"Frame:{f}. Array:{r}")
-
-
-
-
get_cam_ids() → List[int][source]
@@ -139,7 +110,7 @@ np_cam simulates numpy arrays as OpenCV cameras

-pub_cam_thread(cam_id: Union[int, str], request_ize: Tuple[int, int] = (-1, -1), high_speed: bool = True, fps_limit: float = 240) → threading.Thread[source]
+pub_cam_thread(cam_id: Union[int, str], request_ize: Tuple[int, int] = (-1, -1), high_speed: bool = True, fps_limit: float = inf) → threading.Thread[source]

Run pub_cam_loop in a new thread. Starts on creation.

@@ -167,7 +138,6 @@ np_cam simulates numpy arrays as OpenCV cameras

diff --git a/docs/index.html b/docs/index.html index ca458ae..6de11e9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,6 @@ contain the root toctree directive.

  • frame
  • @@ -146,7 +145,7 @@ contain the root toctree directive.

    ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 | diff --git a/docs/input/index.html b/docs/input/index.html index 3cc152c..2d61eca 100644 --- a/docs/input/index.html +++ b/docs/input/index.html @@ -138,7 +138,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12 | diff --git a/docs/objects.inv b/docs/objects.inv index d06227a..0ae0e49 100644 Binary files a/docs/objects.inv and b/docs/objects.inv differ diff --git a/docs/py-modindex/index.html b/docs/py-modindex/index.html index 5c1fbdc..e0fa4d0 100644 --- a/docs/py-modindex/index.html +++ b/docs/py-modindex/index.html @@ -129,7 +129,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12
    diff --git a/docs/search/index.html b/docs/search/index.html index 2c9735c..7c58908 100644 --- a/docs/search/index.html +++ b/docs/search/index.html @@ -110,7 +110,7 @@ ©2019, Simulator Leek. | - Powered by Sphinx 2.2.1 + Powered by Sphinx 2.2.0 & Alabaster 0.7.12
    diff --git a/docs/searchindex.js b/docs/searchindex.js index edd8c42..e3b2582 100644 --- a/docs/searchindex.js +++ b/docs/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["display","displayarray_bash","effects","frame","index","input"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.todo":2,"sphinx.ext.viewcode":1,sphinx:56},filenames:["display.rst","displayarray_bash.rst","effects.rst","frame.rst","index.rst","input.rst"],objects:{"":{displayarray:[0,0,0,"-"]},"displayarray.__main__":{main:[1,1,1,""]},"displayarray.effects":{lens:[2,0,0,"-"]},"displayarray.effects.crop":{Crop:[2,2,1,""]},"displayarray.effects.crop.Crop":{center:[2,3,1,""],enable_mouse_control:[2,3,1,""],output_size:[2,3,1,""]},"displayarray.effects.lens":{Barrel:[2,2,1,""],BarrelPyTorch:[2,2,1,""],ControllableLens:[2,2,1,""],Mustache:[2,2,1,""]},"displayarray.effects.lens.Barrel":{barrel_power:[2,3,1,""],center:[2,3,1,""],enable_mouse_control:[2,3,1,""],zoom:[2,3,1,""]},"displayarray.effects.lens.ControllableLens":{run_bleed:[2,3,1,""]},"displayarray.effects.lens.Mustache":{enable_mouse_control:[2,3,1,""]},"displayarray.effects.select_channels":{SelectChannels:[2,2,1,""]},"displayarray.effects.select_channels.SelectChannels":{enable_mouse_control:[2,3,1,""]},"displayarray.frame":{FrameUpdater:[3,2,1,""],NpCam:[3,2,1,""],get_cam_ids:[3,1,1,""],pub_cam_thread:[3,1,1,""],read_updates:[3,1,1,""]},"displayarray.frame.FrameUpdater":{display:[3,3,1,""],loop:[3,3,1,""]},"displayarray.frame.NpCam":{get:[3,3,1,""],isOpened:[3,3,1,""],read:[3,3,1,""],release:[3,3,1,""],set:[3,3,1,""]},"displayarray.input":{MouseEvent:[5,2,1,""],key_loop:[5,2,1,""],mouse_loop:[5,2,1,""]},"displayarray.window":{SubscriberWindows:[0,2,1,""]},"displayarray.window.SubscriberWindows":{add_callback:[0,3,1,""],add_source:[0,3,1,""],add_window:[0,3,1,""],block:[0,3,1,""],end:[0,3,1,""],handle_keys:[0,3,1,""],handle_mouse:[0,3,1,""],loop:[0,3,1,""],update:[0,3,1,""],update_window_frames:[0,3,1,""],wait_for_init:[0,3,1,""]},displayarray:{__main__:[1,0,0,"-"],breakpoint_display:[0,1,1,""],display:[0,1,1,""],frame:[3,0,0,"-"],read_updates:[3,1,1,""]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:method"},terms:{"class":[0,2,3,5],"default":[1,2,3],"float":3,"function":[0,3,5],"import":3,"int":[0,2,3],"new":[0,3,5],"return":2,"static":3,"true":3,"while":0,For:3,ROS:1,The:0,Use:1,Useful:0,acceler:2,actual:0,adapt:4,add:[0,3],add_callback:0,add_sourc:0,add_window:0,adjust:2,alia:[],all:[0,3,5],allow:0,alt:2,ani:[0,3],anoth:0,api:4,appli:0,arg:[0,3],argument:1,argv:1,arr:[0,2],arrai:[0,1,2,3,4],avoid:2,back:3,backend:1,barrel:2,barrel_pow:2,barrelpytorch:2,bash:4,becom:0,befor:[0,3],block:[0,3],bool:3,breakpoint_displai:0,broker:1,call:3,callabl:[0,3,5],callback:[0,2,3],cam_id:3,camctrl:3,camera:[0,3],can:[0,2,3,4],cap_prop_frame_count:3,cap_prop_frame_height:3,cap_prop_frame_width:3,captur:0,center:2,channel:4,choos:1,chosen:1,close:0,code:0,color:2,com:4,command:[1,3],complet:4,condit:2,contain:4,continu:[0,3,5],control:[0,2,3],controllablelen:2,creat:2,creation:3,crop:4,crop_siz:2,ctrl:2,current:[1,2,3],data:0,decreas:2,def:5,detect:3,dict:[0,3],dictionari:0,did:3,dimension:2,direct:4,displai:[1,2,3,4],display:3,distort:2,divid:2,doctest:[],dtype:1,effect:4,enabl:2,enable_mouse_control:2,end:[0,3],end_callback:3,enumer:3,escap:0,event:[0,5],exampl:3,execut:0,eyebal:[],fake:3,fals:[0,2],file:[0,1,4],filenam:1,finish:3,fix:3,flag:[0,5],food:2,format:[3,5],fps_limit:[0,3],frame:[0,1,4],frameupdat:3,from:[1,2,3],fun:5,get:[2,3],get_cam_id:3,github:4,github_url:4,global:3,guard:2,hack:3,handl:3,handle_kei:0,handle_mous:0,help:1,high_spe:3,hold:5,http:4,ids:3,imag:2,img:3,increas:2,index:4,inf:3,inform:5,init:0,input:[0,2,4],isopen:3,iter:[0,2],kei:[0,4],key_input:0,key_loop:5,know:3,kwarg:[0,3],lambda:3,least:4,len:4,let:3,like:[2,4],limit:2,line:1,link:0,list:[0,2,3],listen:3,loop:[0,2,3],main:[0,1,3],mani:2,messag:1,mode:0,modul:4,mous:[0,2,4],mouse_ev:5,mouse_loop:5,mouseev:5,move:2,msg:1,multipl:3,mustach:2,name:[0,1],ndarrai:[0,3],newest:0,non:0,none:[0,1,2,3,5],nov:4,np_cam:3,npcam:3,number:1,numpi:[0,1,3],onc:0,onli:[0,2,3],open:3,opencv:[0,3,5],oper:[0,3],option:[0,1,3],origin:2,out:2,outer:0,output:2,output_s:2,outsid:3,outward:2,own:0,page:4,param:[0,5],paramet:[2,3],pass:[0,4],pincushion:2,pincushion_pow:2,pleas:3,power:2,press:5,print:[3,5],process:1,program:[0,2],properti:2,pub_cam_loop:3,pub_cam_thread:3,publish:3,python:4,pytorch:2,quickstart:4,read:4,read_upd:3,receiv:[3,5],reduc:[],releas:3,request:3,request_:3,request_s:3,root:4,ros:1,run:[3,5],run_ble:2,scale:3,screen:3,scroll:2,search:4,see:[],select:4,select_channel:[],selectchannel:2,selected_channel:2,send:3,set:3,shift:2,should:[0,4],show:1,simleek:4,simul:3,sinc:3,size:[0,2,3],someth:3,sourc:[0,1,2,3,5],specif:3,sphinx:4,spread:2,standard:3,start:3,stop:0,str:[0,3,5],subscrib:0,subscriberwindow:0,support:[1,2],tell:3,test_video:3,text:1,thei:0,them:3,thi:[0,1,3,4],thread:[0,3,5],three:[],thu:4,titl:0,toctre:4,too:2,topic:1,tupl:3,union:[0,3],until:[0,3],updat:[0,4],update_window_fram:0,usag:[1,3],use:3,use_ble:2,used:0,user:2,using:1,version:1,vid:[0,3],video:[0,1,3],video_sourc:[0,3],videohandlerthread:3,wait:0,wait_for_init:0,water:2,webcam:[0,1],wheel:2,where:2,window:[4,5],window_nam:0,within:2,work:3,you:4,your:4,zero:2,zeromq:1,zoom:2},titles:["displayarray.display","displayarray cli","displayarray.effects","displayarray.frame","DisplayArray Documentation","displayarray.input"],titleterms:{channel:2,cli:1,crop:2,displai:0,displayarrai:[0,1,2,3,4,5],document:4,effect:2,frame:3,indic:4,input:5,kei:5,len:2,mous:5,pass:3,read:3,select:2,select_channel:[],tabl:4,updat:3,window:0}}) \ No newline at end of file +Search.setIndex({docnames:["display","displayarray_bash","effects","frame","index","input"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.todo":2,"sphinx.ext.viewcode":1,sphinx:56},filenames:["display.rst","displayarray_bash.rst","effects.rst","frame.rst","index.rst","input.rst"],objects:{"":{displayarray:[0,0,0,"-"]},"displayarray.__main__":{main:[1,1,1,""]},"displayarray.effects":{lens:[2,0,0,"-"]},"displayarray.effects.crop":{Crop:[2,2,1,""]},"displayarray.effects.crop.Crop":{center:[2,3,1,""],enable_mouse_control:[2,3,1,""],output_size:[2,3,1,""]},"displayarray.effects.lens":{Barrel:[2,2,1,""],BarrelPyTorch:[2,2,1,""],ControllableLens:[2,2,1,""],Mustache:[2,2,1,""]},"displayarray.effects.lens.Barrel":{barrel_power:[2,3,1,""],center:[2,3,1,""],enable_mouse_control:[2,3,1,""],zoom:[2,3,1,""]},"displayarray.effects.lens.ControllableLens":{run_bleed:[2,3,1,""]},"displayarray.effects.lens.Mustache":{enable_mouse_control:[2,3,1,""]},"displayarray.effects.select_channels":{SelectChannels:[2,2,1,""]},"displayarray.effects.select_channels.SelectChannels":{enable_mouse_control:[2,3,1,""]},"displayarray.frame":{FrameUpdater:[3,2,1,""],NpCam:[3,2,1,""],get_cam_ids:[3,1,1,""],pub_cam_thread:[3,1,1,""]},"displayarray.frame.FrameUpdater":{display:[3,3,1,""],loop:[3,3,1,""]},"displayarray.frame.NpCam":{get:[3,3,1,""],isOpened:[3,3,1,""],read:[3,3,1,""],release:[3,3,1,""],set:[3,3,1,""]},"displayarray.input":{MouseEvent:[5,2,1,""],key_loop:[5,2,1,""],mouse_loop:[5,2,1,""]},"displayarray.window":{SubscriberWindows:[0,2,1,""]},"displayarray.window.SubscriberWindows":{add_callback:[0,3,1,""],add_source:[0,3,1,""],add_window:[0,3,1,""],block:[0,3,1,""],end:[0,3,1,""],handle_keys:[0,3,1,""],handle_mouse:[0,3,1,""],loop:[0,3,1,""],update:[0,3,1,""],update_frames:[0,3,1,""],wait_for_init:[0,3,1,""]},displayarray:{__main__:[1,0,0,"-"],breakpoint_display:[0,1,1,""],display:[0,1,1,""],frame:[3,0,0,"-"],read_updates:[0,1,1,""]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:method"},terms:{"class":[0,2,3,5],"default":[1,2,3],"float":3,"function":[0,5],"import":[],"int":[0,2,3],"new":[0,3,5],"return":2,"static":3,"true":3,"while":0,For:3,ROS:1,The:0,Use:1,Useful:0,acceler:2,actual:0,adapt:4,add:[0,3],add_callback:0,add_sourc:0,add_window:0,adjust:2,alia:[],all:[0,3,5],allow:0,alt:2,ani:[0,3],anoth:0,api:4,appli:0,arg:[0,3],argument:1,argv:1,arr:[0,2],arrai:[0,1,2,3,4],avoid:2,back:[0,3],backend:1,barrel:2,barrel_pow:2,barrelpytorch:2,bash:4,becom:0,befor:[0,3],block:0,bool:[0,3],breakpoint_displai:0,broker:1,call:3,callabl:[0,3,5],callback:[0,2,3],cam_id:3,camctrl:3,camera:[0,3],can:[0,2,3,4],cap_prop_frame_count:3,cap_prop_frame_height:3,cap_prop_frame_width:3,captur:0,center:2,channel:4,choos:1,chosen:1,close:0,code:0,color:2,com:4,command:[1,3],complet:4,condit:2,contain:4,continu:[0,3,5],control:[0,2,3],controllablelen:2,creat:2,creation:3,crop:4,crop_siz:2,ctrl:2,current:[1,2,3],data:0,decreas:2,def:5,detect:3,dict:0,dictionari:0,did:3,dimension:2,direct:4,displai:[1,2,3,4],display:3,distort:2,divid:2,doctest:[],dtype:1,effect:4,empti:0,enabl:2,enable_mouse_control:2,end:[0,3],end_callback:[],enumer:[],escap:0,event:[0,5],exampl:[],execut:0,eyebal:[],fake:3,fals:[0,2],file:[0,1,4],filenam:1,finish:3,fix:3,flag:[0,5],food:2,format:[3,5],fps_limit:[0,3],frame:[0,1,4],frameupdat:3,from:[1,2,3],fun:5,get:[2,3],get_cam_id:3,github:4,github_url:4,global:3,guard:2,hack:3,handl:3,handle_kei:0,handle_mous:0,help:1,high_spe:3,hold:5,http:4,ids:3,imag:2,img:3,increas:2,index:4,inf:[0,3],inform:5,init:0,input:[0,2,4],isopen:3,iter:[0,2],kei:[0,4],key_input:0,key_loop:5,know:3,kwarg:[0,3],lambda:[],least:4,len:4,let:3,like:[2,4],limit:2,line:1,link:0,list:[0,2,3],listen:3,loop:[0,2,3],main:[0,1,3],mani:2,messag:1,mode:0,modul:4,mous:[0,2,4],mouse_ev:5,mouse_loop:5,mouseev:5,move:2,msg:1,multipl:3,mustach:2,name:[0,1],ndarrai:[0,3],newest:0,non:0,none:[0,1,2,3,5],nov:4,np_cam:3,npcam:3,number:1,numpi:[0,1,3],onc:0,onli:[0,2,3],open:3,opencv:[0,3,5],oper:[0,3],option:[0,1,3],origin:2,out:2,outer:0,output:2,output_s:2,outsid:3,outward:2,own:0,page:4,param:[0,5],paramet:[2,3],pass:[0,4],pincushion:2,pincushion_pow:2,pleas:3,power:2,press:5,print:5,process:1,program:[0,2],properti:2,pub_cam_loop:3,pub_cam_thread:3,publish:3,python:4,pytorch:2,quickstart:4,read:[0,3],read_upd:0,receiv:[3,5],reduc:[],releas:3,request:[],request_:3,request_s:3,root:4,ros:1,run:[3,5],run_ble:2,scale:3,screen:3,scroll:2,search:4,see:[],select:4,select_channel:[],selectchannel:2,selected_channel:2,send:3,set:3,shift:2,should:[0,4],show:1,silent:0,simleek:4,simul:3,sinc:3,size:[0,2,3],someth:3,sourc:[0,1,2,3,5],specif:3,sphinx:4,spread:2,standard:3,start:3,stop:0,str:[0,3,5],subscrib:0,subscriberwindow:0,support:[1,2],tell:3,test_video:[],text:1,thei:0,them:3,thi:[0,1,3,4],thread:[0,3,5],three:[],thu:4,titl:0,toctre:4,too:2,topic:1,tupl:3,union:[0,3],until:[0,3],updat:[0,3],update_fram:0,update_window_fram:[],usag:1,use:3,use_ble:2,used:0,user:2,using:1,version:1,vid:0,video:[0,1,3],video_sourc:[0,3],videohandlerthread:3,wait:0,wait_for_init:0,water:2,webcam:[0,1],were:0,wheel:2,where:2,window:[4,5],window_nam:0,within:2,work:3,yield:0,you:4,your:4,zero:2,zeromq:1,zoom:2},titles:["displayarray.display","displayarray cli","displayarray.effects","displayarray.frame","DisplayArray Documentation","displayarray.input"],titleterms:{channel:2,cli:1,crop:2,displai:0,displayarrai:[0,1,2,3,4,5],document:4,effect:2,frame:3,indic:4,input:5,kei:5,len:2,mous:5,pass:3,read:[],select:2,select_channel:[],tabl:4,updat:[],window:0}}) \ No newline at end of file diff --git a/examples/callbacks/black_and_white.py b/examples/callbacks/black_and_white.py index 62a530e..f7e050d 100644 --- a/examples/callbacks/black_and_white.py +++ b/examples/callbacks/black_and_white.py @@ -6,4 +6,11 @@ def black_and_white(arr): return (np.sum(arr, axis=-1) / 3).astype(np.uint8) -display(0, callbacks=black_and_white, blocking=True) +import time + +t0 = t1 = time.time() +for up in display(0, size=(1, 1), callbacks=black_and_white): + if up: + t1 = time.time() + print(1.0 / (t1 - t0)) + t0 = t1 diff --git a/examples/looping/no_display.py b/examples/looping/no_display.py new file mode 100644 index 0000000..5d035b8 --- /dev/null +++ b/examples/looping/no_display.py @@ -0,0 +1,30 @@ +from displayarray import read_updates, end_feeds +import time +import cProfile +from examples.videos import test_video + + +def profile_reading(total_seconds=2): + t_init = t01 = time.time() + times = [] + started = False + for up in read_updates(test_video, size=(1, 1)): + if up: + t1 = time.time() + if started: + times.append((t1 - t01) * 1000) + t01 = t1 + started = True + if started: + t2 = time.time() + if t2 - t_init >= total_seconds: + if times: + print(f"Average framerate: {1000 / (sum(times) / len(times))}fps") + else: + print("failure") + break + else: + t_init = time.time() + + +cProfile.run("profile_reading()") diff --git a/examples/looping/no_display_simple.py b/examples/looping/no_display_simple.py new file mode 100644 index 0000000..6ee53b1 --- /dev/null +++ b/examples/looping/no_display_simple.py @@ -0,0 +1,6 @@ +from displayarray import read_updates + +for f in read_updates(0, size=(1, 1)): + if f: + print(f[0].shape) + break diff --git a/pyproject.toml b/pyproject.toml index f32c23d..b292ba6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'displayarray' -version = '0.7.2' +version = '0.7.3' description = 'Tool for displaying numpy arrays.' authors = ['SimLeek '] license = 'MIT' diff --git a/tests/frame/test_frame_publishing.py b/tests/frame/test_frame_publishing.py index 840c8b4..1b4c8d0 100644 --- a/tests/frame/test_frame_publishing.py +++ b/tests/frame/test_frame_publishing.py @@ -145,6 +145,6 @@ def test_pub_cam_thread(): pub_cam_thread(5) mock_thread.assert_called_once_with( - target=fpub.pub_cam_loop, args=(5, (-1, -1), True, 240) + target=fpub.pub_cam_loop, args=(5, (-1, -1), True, float("inf")) ) thread_instance.start.assert_called_once() diff --git a/tests/frame/test_frame_updater.py b/tests/frame/test_frame_updater.py index 6c3aa78..3230511 100644 --- a/tests/frame/test_frame_updater.py +++ b/tests/frame/test_frame_updater.py @@ -14,7 +14,7 @@ def test_init_defaults(): assert ud.callbacks == [] assert ud.request_size == (-1, -1) assert ud.high_speed == True - assert ud.fps_limit == 240 + assert ud.fps_limit == float("inf") def test_init(): @@ -57,7 +57,7 @@ def test_loop(): ud.loop() - mock_pubcam_thread.assert_called_once_with(0, (-1, -1), True, 240) + mock_pubcam_thread.assert_called_once_with(0, (-1, -1), True, float("inf")) mock_frame_sub.assert_called_once_with("0") handler_cmd_sub.assert_called_once_with("0") sub_cam.get.assert_has_calls([mock.call(blocking=True, timeout=1.0)] * 3) diff --git a/tests/window/test_subscriber_windows.py b/tests/window/test_subscriber_windows.py index b8c1836..cebd20d 100644 --- a/tests/window/test_subscriber_windows.py +++ b/tests/window/test_subscriber_windows.py @@ -181,7 +181,7 @@ def test_handle_mouse(): mock_win_cmd.mouse_pub.publish.assert_called_once_with(mock_mousey) -def test_update_window_frames(): +def test_update_frames(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( cv2, "imshow" @@ -191,13 +191,13 @@ def test_update_window_frames(): frame = np.ones((100, 100)) sw.FRAME_DICT["0"] = frame - sw.update_window_frames() + sw.update_frames() assert sw.frames == [frame] mock_imshow.assert_called_once_with("displayarray (press ESC to quit)", frame) -def test_update_window_frames_callback(): +def test_update_frames_callback(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( cv2, "imshow" @@ -217,7 +217,7 @@ def test_update_window_frames_callback(): sw.FRAME_DICT["0"] = frame sw.FRAME_DICT["1"] = frame - sw.update_window_frames() + sw.update_frames() assert sw.frames == [frame3, frame3] assert np.all(cb.mock_calls[0].args[0] == frame) @@ -230,7 +230,7 @@ def test_update_window_frames_callback(): ) -def test_update_window_frames_too_many_channels(): +def test_update_frames_too_many_channels(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( cv2, "imshow" @@ -242,7 +242,7 @@ def test_update_window_frames_too_many_channels(): frame = np.ones((100, 100, 100)) sw.FRAME_DICT["0"] = frame - sw.update_window_frames() + sw.update_frames() mock_print.assert_has_calls( [ @@ -263,7 +263,7 @@ def test_update_window_frames_too_many_channels(): assert sw.frames[0].shape[-1] == 3 -def test_update_window_frames_nested(): +def test_update_frames_nested(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( cv2, "imshow" @@ -273,7 +273,7 @@ def test_update_window_frames_nested(): frame = np.ones((20, 100, 100, 100)) sw.FRAME_DICT["0"] = frame - sw.update_window_frames() + sw.update_frames() assert np.all(sw.frames[0] == np.ones((20, 100, 100, 3))) assert len(sw.frames) == 1 @@ -319,7 +319,7 @@ def test_update_window_frames_nested(): assert np.all(mock_imshow.mock_calls[19].args[1] == np.ones((100, 100, 3))) -def test_update_window_frames_exception(): +def test_update_frames_exception(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( cv2, "imshow" @@ -330,14 +330,14 @@ def test_update_window_frames_exception(): sw.FRAME_DICT["0"] = frame with pytest.raises(RuntimeError) as e: - sw.update_window_frames() + sw.update_frames() assert e.value == frame def test_update(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( - sub_win.SubscriberWindows, "update_window_frames" + sub_win.SubscriberWindows, "update_frames" ) as mock_update_win_frames, mock.patch( "displayarray.window.subscriber_windows.window_commands" ) as mock_win_cmd, mock.patch.object( @@ -364,7 +364,7 @@ def test_update(): def test_update_with_array(): sub_win.SubscriberWindows.FRAME_DICT = {} with mock.patch.object(cv2, "namedWindow"), mock.patch.object( - sub_win.SubscriberWindows, "update_window_frames" + sub_win.SubscriberWindows, "update_frames" ) as mock_update_win_frames, mock.patch( "displayarray.window.subscriber_windows.window_commands" ) as mock_win_cmd, mock.patch.object( @@ -495,13 +495,13 @@ def test_display(): fup.assert_has_calls( [ - mock.call(0, fps_limit=240, request_size=(50, 50)), - mock.call(1, fps_limit=240, request_size=(50, 50)), + mock.call(0, fps_limit=float("inf"), request_size=(50, 50)), + mock.call(1, fps_limit=float("inf"), request_size=(50, 50)), ] ) assert fup_inst.start.call_count == 2 sws.assert_called_once_with( - window_names=["window 0", "window 1"], video_sources=(0, 1) + window_names=["window 0", "window 1"], video_sources=(0, 1), silent=False ) assert sws_inst.close_threads == [fup_inst, fup_inst] assert d == sws_inst @@ -521,7 +521,7 @@ def test_display_blocking(): assert fup_inst.start.call_count == 2 sws.assert_called_once_with( - window_names=["window 0", "window 1"], video_sources=(0, 1) + window_names=["window 0", "window 1"], video_sources=(0, 1), silent=False ) sws_inst.loop.assert_called_once() assert fup_inst.join.call_count == 2 @@ -540,8 +540,12 @@ def test_display_callbacks(): fup.assert_has_calls( [ - mock.call(0, callbacks=[cb], fps_limit=240, request_size=(-1, -1)), - mock.call(1, callbacks=[cb], fps_limit=240, request_size=(-1, -1)), + mock.call( + 0, callbacks=[cb], fps_limit=float("inf"), request_size=(-1, -1) + ), + mock.call( + 1, callbacks=[cb], fps_limit=float("inf"), request_size=(-1, -1) + ), ] ) @@ -574,10 +578,17 @@ def test_display_callbacks_dict(): fup.assert_has_calls( [ - mock.call(0, callbacks=[cb1], fps_limit=240, request_size=(-1, -1)), mock.call( - 1, callbacks=[cb1, cb2], fps_limit=240, request_size=(-1, -1) + 0, callbacks=[cb1], fps_limit=float("inf"), request_size=(-1, -1) + ), + mock.call( + 1, + callbacks=[cb1, cb2], + fps_limit=float("inf"), + request_size=(-1, -1), + ), + mock.call( + 2, callbacks=[cb3], fps_limit=float("inf"), request_size=(-1, -1) ), - mock.call(2, callbacks=[cb3], fps_limit=240, request_size=(-1, -1)), ] )