Ejemplo n.º 1
0
 def end(self):
     """Close all threads. Should be used with non-blocking mode."""
     window_commands.quit(force_all_read=False)
     self.__stop_all_cams()
     if self.close_threads is not None:
         for t in self.close_threads:
             t.join()
Ejemplo n.º 2
0
 def _run_finisher(self, frame, finished, *args, **kwargs):
     if not callable(finish_function):
         window_commands.quit()
     else:
         finished = finish_function(frame, Ellipsis, finished, *args,
                                    **kwargs)
         if finished:
             window_commands.quit()
Ejemplo n.º 3
0
 def loop(self):
     """Continually update window frame. OpenCV only allows this in the main thread."""
     sub_cmd = window_commands.win_cmd_sub()
     msg_cmd = ""
     key = ""
     while msg_cmd != "quit" and key != "quit":
         msg_cmd, key = self.update()
     sub_cmd.release()
     window_commands.quit(force_all_read=False)
     self.__stop_all_cams()
Ejemplo n.º 4
0
 def __call__(self, *args, **kwargs):
     """Run the function this was set up with in a loop."""
     msg_cmd = ""
     while msg_cmd != "quit":
         key_chr = self.sub_key.get()  # type: chr
         if key_chr is not self.sub_key.return_on_no_data:
             self.f(key_chr, *args, **kwargs)
         elif self.run_when_no_events:
             self.f(None, *args, **kwargs)
         msg_cmd = self.sub_cmd.get()
         time.sleep(1.0 / self.fps)
     window_commands.quit(force_all_read=False)
Ejemplo n.º 5
0
 def __call__(self, *args, **kwargs):
     """Run the function this was set up with in a loop."""
     msg_cmd = ""
     while msg_cmd != "quit":
         mouse_xyzclick = self.sub_mouse.get(
             blocking=True)  # type: MouseEvent
         if mouse_xyzclick is not self.sub_mouse.return_on_no_data:
             self.f(mouse_xyzclick, *args, **kwargs)
         elif self.run_when_no_events:
             self.f(None, *args, **kwargs)
         msg_cmd = self.sub_cmd.get()
         time.sleep(1.0 / self.fps)
     window_commands.quit(force_all_read=False)
Ejemplo n.º 6
0
 def __apply_callbacks_to_frame(self, frame):
     if frame is not None:
         frame_c = None
         for c in self.callbacks:
             try:
                 frame_c = c(frame)
             except TypeError as te:
                 raise TypeError(
                     "Callback functions for cvpubsub need to accept two arguments: array and uid"
                 )
             except Exception as e:
                 self.exception_raised = e
                 frame = frame_c = self.exception_raised
                 subscriber_dictionary.stop_cam(self.cam_id)
                 window_commands.quit()
                 raise e
         if frame_c is not None:
             global_cv_display_callback(frame_c, self.cam_id)
         else:
             global_cv_display_callback(frame, self.cam_id)
Ejemplo n.º 7
0
 def handle_keys(
         self, key_input  # type: int
 ):
     """Capture key input for the escape function and passing to key control subscriber threads."""
     if key_input in self.ESC_KEY_CODES:
         for name in self.window_names:
             cv2.destroyWindow(name + " (press ESC to quit)")
         self.exited = True
         window_commands.quit()
         self.__stop_all_cams()
         return "quit"
     elif key_input not in [-1, 0]:
         try:
             window_commands.key_pub.publish(chr(key_input))
         except ValueError:
             warnings.warn(
                 RuntimeWarning(
                     "Unknown key code: [{}]. Please report to cv_pubsubs issue page.".format(
                         key_input
                     )
                 )
             )