Example #1
0
    def update(self):
        """run the thread"""
        last_time = time.time()
        num_frames = 0
        while not self.stopped:
            current_time = time.time()

            _, img = self.cam.read()
            num_frames += 1
            self.frame_time = int(current_time * 1000)

            if (img is not None) and (not self.capture.full()):

                if (self._output_height > 0) or (self._flip_method > 0):
                    # adjust output height
                    img_resized = cv2.resize(img, self._output_res)
                    # flip resized image
                    if self._flip_method == 0:  # no flipping
                        img_proc = img_resized
                    elif self._flip_method == 1:  # ccw 90
                        img_proc = cv2.roate(img_resized,
                                             cv2.ROTATE_90_COUNTERCLOCKWISE)
                    elif self._flip_method == 2:  # rot 180, same as flip lr & up
                        img_proc = cv2.roate(img_resized, cv2.ROTATE_180)
                    elif self._flip_method == 3:  # cw 90
                        img_proc = cv2.roate(img_resized,
                                             cv2.ROTATE_90_CLOCKWISE)
                    elif self._flip_method == 4:  # horizontal
                        img_proc = cv2.flip(img_resized, 0)
                    elif self._flip_method == 5:  # upright diagonal. ccw & lr
                        img_proc = cv2.flip(
                            cv2.roate(img_resized,
                                      cv2.ROTATE_90_COUNTERCLOCKWISE), 1)
                    elif self._flip_method == 6:  # vertical
                        img_proc = cv2.flip(img_resized, 1)
                    elif self._flip_method == 7:  # upperleft diagonal
                        img_proc = cv2.transpose(img_resized)
                    else:
                        img_proc = img_resized  # not a valid flip method
                else:
                    img_proc = img

                self.capture.put_nowait((self.frame_time, img_proc))
            else:
                if not self.log.full():
                    self.log.put_nowait(
                        (logging.WARNING, "RTSPCap:Capture Queue is full!"))

            # FPS calculation
            if (current_time -
                    last_time) >= 5.0:  # update frame rate every 5 secs
                self.measured_fps = num_frames / 5.0
                if not self.log.full():
                    self.log.put_nowait(
                        (logging.INFO,
                         "RTSPCAM:FPS:{}".format(self.measured_fps)))
                num_frames = 0
                last_time = current_time

        self.cam.release()
Example #2
0
    def update(self):
        """Run the process"""

        # open up the camera
        self._open_capture()

        # initialize variables
        last_time = time.time()
        num_frames = 0

        while not self.stopper.is_set():
            
            # Capture image
            current_time = time.time()
            _, img = self.cam.read()
            num_frames += 1
            
            if (img is not None) and (not self.capture.full()):
                if (self._output_height > 0) or (self._flip_method > 0):
                    # adjust output height
                    img_resized = cv2.resize(img, self._output_res)
                    # flip resized image
                    if   self._flip_method == 0: # no flipping
                        img_proc = img_resized
                    elif self._flip_method == 1: # ccw 90
                        img_proc = cv2.roate(img_resized, cv2.ROTATE_90_COUNTERCLOCKWISE)
                    elif self._flip_method == 2: # rot 180, same as flip lr & up
                        img_proc = cv2.roate(img_resized, cv2.ROTATE_180)
                    elif self._flip_method == 3: # cw 90
                        img_proc = cv2.roate(img_resized, cv2.ROTATE_90_CLOCKWISE)
                    elif self._flip_method == 4: # horizontal
                        img_proc = cv2.flip(img_resized, 0)
                    elif self._flip_method == 5: # upright diagonal. ccw & lr
                        img_proc = cv2.flip(cv2.roate(img_resized, cv2.ROTATE_90_COUNTERCLOCKWISE), 1)
                    elif self._flip_method == 6: # vertical
                        img_proc = cv2.flip(img_resized, 1)
                    elif self._flip_method == 7: # upperleft diagonal
                        img_proc = cv2.transpose(img_resized)
                    else:
                        img_proc = img_resized # not a valid flip method
                else:
                    img_proc = img

                self.capture.put_nowait((current_time*1000., img_proc))
            else:
                if not self.log.full(): self.log.put_nowait((logging.WARNING, "CV2:Capture queue is full!"))

            # FPS calculation
            if (current_time - last_time) >= 5.0: # update frame rate every 5 secs
                self.log.put_nowait((logging.INFO, "CV2CAM:FPS:{}".format(num_frames/5.0)))
                num_frames = 0
                last_time = current_time

        self.cam.release()      
Example #3
0
    def update(self):
        """ run the thread """
        last_fps_time = time.time()
        last_exposure_time = last_fps_time
        num_frames = 0
        while not self.stopped:
            current_time = time.time()
            # FPS calculation
            if (current_time - last_fps_time) >= 5.0: # update frame rate every 5 secs
                self.measured_fps = num_frames/5.0
                self.logger.log(logging.DEBUG, "Status:FPS:{}".format(self.measured_fps))
                num_frames = 0
                last_fps_time = current_time
            with self.capture_lock:
                _, img = self.capture.read()

            if img is not None:

                # adjust output height
                if self._display_height > 0:
                    # tmp = cv2.resize(img, self._display_res, interpolation = cv2.INTER_NEAREST)
                    tmp = cv2.resize(img, self._display_res)
                else:
                    tmp = img

                # flip image if needed
                if   self._flip_method == 1: # ccw 90
                    self.frame = cv2.roate(tmp, cv2.ROTATE_90_COUNTERCLOCKWISE)
                elif self._flip_method == 2: # rot 180, same as flip lr & up
                    self.frame = cv2.roate(tmp, cv2.ROTATE_180)
                elif self._flip_method == 3: # cw 90
                    self.frame = cv2.roate(tmp, cv2.ROTATE_90_COUNTERCLOCKWISE)
                elif self._flip_method == 4: # horizontal
                    self.frame = cv2.flip(tmp, 0)
                elif self._flip_method == 5: # upright diagonal. ccw & lr
                    tmp = cv2.roate(tmp, cv2.ROTATE_90_COUNTERCLOCKWISE)
                    self.frame = cv2.flip(tmp, 1)
                elif self._flip_method == 6: # vertical
                    self.frame = cv2.flip(tmp, 1)
                elif self._flip_method == 7: # upperleft diagonal
                    self.frame = cv2.transpose(tmp)
                else:
                    self.frame = tmp

                num_frames += 1

            if self.stopped:
                self.capture.release()        
Example #4
0
    def update(self):
        """ run the thread """
        last_fps_time = time.time()
        last_exposure_time = last_fps_time
        num_frames = 0
        for f in self.stream:
            current_time = time.time()
            # FPS calculation
            if (current_time -
                    last_fps_time) >= 5.0:  # update frame rate every 5 secs
                self.measured_fps = num_frames / 5.0
                self.logger.log(logging.DEBUG,
                                "Status:FPS:{}".format(self.measured_fps))
                num_frames = 0
                last_fps_time = current_time
            with self.capture_lock:
                img = f.array
                self.rawCapture.truncate(0)
            # set the frame var to the img we just captured
            if self._display_height > 0:
                tmp = cv2.resize(img, self._display_res)
            else:
                tmp = img

            if self._flip_method == 1:  # ccw 90
                self.frame = cv2.roate(tmp, cv.ROTATE_90_COUNTERCLOCKWISE)
            elif self._flip_method == 2:  # rot 180, same as flip lr & up
                self.frame = cv2.roate(tmp, cv.ROTATE_180)
            elif self._flip_method == 3:  # cw 90
                self.frame = cv2.roate(tmp, cv.ROTATE_90_COUNTERCLOCKWISE)
            elif self._flip_method == 4:  # horizontal
                self.frame = cv2.flip(tmp, 0)
            elif self._flip_method == 5:  # upright diagonal. ccw & lr
                tmp = cv2.roate(tmp, cv.ROTATE_90_COUNTERCLOCKWISE)
                self.frame = cv2.flip(tmp, 1)
            elif self._flip_method == 6:  # vertical
                self.frame = cv2.flip(tmp, 1)
            elif self._flip_method == 7:  # upperleft diagonal
                self.frame = cv2.transpose(tmp)

            num_frames += 1

            if self.stopped:
                self.stream.close()
                self.rawCapture.close()
                self.capture.close()
Example #5
0
    def update(self):
        """ run the thread """
        try:
            self.stream = self.cam.capture_continuous(self.rawCapture,
                                                      format="bgr",
                                                      use_video_port=True)
        except:
            if not self.log.full():
                self.log.put_nowait((logging.CRITICAL,
                                     "PiCap:Failed to create camera stream!"))

        last_time = time.time()
        num_frames = 0

        for f in self.stream:
            current_time = time.time()

            img = f.array
            self.rawCapture.truncate(0)
            num_frames += 1
            self.frame_time = int(current_time * 1000)

            if (img is not None) and (not self.capture.full()):

                if (self._output_height > 0) or (self._flip_method > 0):
                    # adjust output height
                    img_resized = cv2.resize(img, self._output_res)
                    # flip resized image
                    if self._flip_method == 0:  # no flipping
                        img_proc = img_resized
                    elif self._flip_method == 1:  # ccw 90
                        img_proc = cv2.roate(img_resized,
                                             cv2.ROTATE_90_COUNTERCLOCKWISE)
                    elif self._flip_method == 2:  # rot 180, same as flip lr & up
                        img_proc = cv2.roate(img_resized, cv2.ROTATE_180)
                    elif self._flip_method == 3:  # cw 90
                        img_proc = cv2.roate(img_resized,
                                             cv2.ROTATE_90_CLOCKWISE)
                    elif self._flip_method == 4:  # horizontal
                        img_proc = cv2.flip(img_resized, 0)
                    elif self._flip_method == 5:  # upright diagonal. ccw & lr
                        img_proc = cv2.flip(
                            cv2.roate(img_resized,
                                      cv2.ROTATE_90_COUNTERCLOCKWISE), 1)
                    elif self._flip_method == 6:  # vertical
                        img_proc = cv2.flip(img_resized, 1)
                    elif self._flip_method == 7:  # upperleft diagonal
                        img_proc = cv2.transpose(img_resized)
                    else:
                        img_proc = img_resized  # not a valid flip method
                else:
                    img_proc = img

                self.capture.put_nowait((self.frame_time, img_proc))
            else:
                if not self.log.full():
                    self.log.put_nowait(
                        (logging.WARNING, "PiCap:Capture Queue is full!"))

            # FPS calculation
            if (current_time -
                    last_time) >= 5.0:  # update frame rate every 5 secs
                self.measured_fps = num_frames / 5.0
                if not self.log.full():
                    self.log.put_nowait(
                        (logging.INFO,
                         "PICAM:FPS:{}".format(self.measured_fps)))
                num_frames = 0
                last_time = current_time

        self.stream.close()
        self.rawCapture.close()
        self.cam.close()