Beispiel #1
0
 def __init__(self, title, x, y, width, height, device=0):
     super(MainView, self).__init__(title, x, y, width, height)
     self.video_capture = ZOpenCVVideoCapture()
     self.video_capture.open(device)
     self.image_view = ZOpenCVImageView(self)
     self.add(self.image_view)
     title = str(device)
     self.set_filenamed_title(title)
     self.show()
Beispiel #2
0
class MainView(ZApplicationView):

    # Constructor
    def __init__(self, title, x, y, width, height, device=0):
        super(MainView, self).__init__(title, x, y, width, height)
        self.video_capture = ZOpenCVVideoCapture()
        self.video_capture.open(device)
        self.image_view = ZOpenCVImageView(self)
        self.add(self.image_view)
        title = str(device)
        self.set_filenamed_title(title)
        self.show()

    # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view
    def render(self):
        if self.video_capture.is_opened():
            frame = self.video_capture.read()
            if frame.any() != None:
                self.image_view.set_opencv_image(frame)
                self.image_view.update()
                return True
        else:
            # If the video_capture closed, return False
            return False

    # Show FileOpenDialog and select an image file.
    def file_open(self):
        options = QFileDialog.Options()
        filename, _ = QFileDialog.getOpenFileName(
            self,
            "FileOpenDialog",
            "",
            "All Files (*);;Image Files (*.png;*jpg;*.jpeg)",
            options=options)
        if filename:
            self.video_capture.close()
            self.video_capture.open(filename)
            self.set_filenamed_title(filename)

    def file_quit(self):
        self.terminated = True
        self.video_capture.close()
        self.close()
Beispiel #3
0
class MainView(ZApplicationView):
  
  # Constructor
  def __init__(self, title, x, y, width, height, device=0):
    super(MainView, self).__init__(title, x, y, width, height)
    self.video_capture = ZOpenCVVideoCapture()
    self.video_capture.open(device)
    self.image_view  = ZOpenCVImageView(self)
    self.add(self.image_view)
    
    title = str(device) + " - " + name
    self.setWindowTitle(title)
    
    self.show()
  
  # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view     
  def render(self):
    if self.video_capture.is_opened():
      frame = self.video_capture.read()
      if frame.any() != None:
        self.image_view.set_opencv_image(frame)
        self.image_view.update()
        return True
    else:
      # If the video_capture closed, return False
      return False
 
  def file_quit(self):
    self.terminated = True
    self.video_capture.close()
    self.close()
Beispiel #4
0
def cam_process(raw_video_queue, device=0):
    video_capture = ZOpenCVVideoCapture()
    video_capture.open(device)

    # Get a raw frame
    #frame = video_capture.read()

    #nrows, ncols, ncs = frame.shape

    # Get optimal dft si

    # fps limit settings
    time_snapshot_seconds = time()
    fps_limit_hz = 10

    while True:
        if video_capture.is_opened():
            frame = video_capture.read()

            current_time_seconds = time()

            if current_time_seconds > time_snapshot_seconds:  # Avoid dividing by zero
                if ((1 / (current_time_seconds - time_snapshot_seconds)) <=
                        fps_limit_hz):  # Rate limit
                    gray_image = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
                    #raw_video_queue.put(frame)
                    raw_video_queue.put_nowait(gray_image)  # non-blocking

                    time_snapshot_seconds = current_time_seconds
Beispiel #5
0
def cam_process(raw_video_queue, device=0):
  video_capture = ZOpenCVVideoCapture()
  video_capture.open(device)
  while True:
    if video_capture.is_opened():
        frame = video_capture.read()
        #raw_video_queue.put(frame)
        raw_video_queue.put_nowait(frame) # non-blocking
Beispiel #6
0
def cam_process(message_queue, raw_video_queue, device=0):
    video_capture = ZOpenCVVideoCapture()
    video_capture.open(device)
    while True:
        try:
            """
      if not message_queue.empty():
        if message_queue.get() == "exit":
          print("fskdnhbfkjsdbhfhbk")
          #video_capture.close()
          #message_queue.close()
          #raw_video_queue.close()
          break
      """
            if video_capture.is_opened():
                frame = video_capture.read()
                raw_video_queue.put(frame)
                #raw_video_queue.put_nowait(frame) # non-blocking
        except KeyboardInterrupt:
            print("ignore CTRL-C from worker")
            print("to terminate child process correctly")
    print("Here")