Пример #1
0
    def play_video(self):
        """Create a window and play the video stored in video_array. 
        generate_video will be run automatically if it has not been run.
        
        Parameters
        -----------
        waitKey : int, optional
            Time (ms) delay between showing each frame.
        """
        temp_filename = self.temp_filename

        window_name = temp_filename[(temp_filename.rfind('/') + 1):]
        cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
        cv2.resizeWindow(window_name, 640, 480)

        print(
            "'K' - Play/Pause | 'J' - Rewind 10 frames | 'L' - Fast Forward 10 frames | 'Q' - Quit"
        )

        frame_num = 0
        pause = False
        while True:
            #TODO:  Change progressbar to show timestamp (relative to video)
            #       instead of percentage
            progress_bar.printProgressBar(frame_num,
                                          self.num_frames - 1,
                                          prefix='Playing Video: ')
            key = cv2.waitKey(self.frame_delay)
            if key == ord("q"):
                break
            elif key == ord("k"):
                pause = not pause
            elif key == ord("l"):
                if frame_num < self.num_frames - 11:
                    frame_num += 10
                else:
                    frame_num = self.num_frames - 1
            elif key == ord("j"):
                if frame_num > 10:
                    frame_num -= 10
                else:
                    frame_num = 0

            if not pause:
                frame_num += 1
            else:
                pass

            img = self.generate_frame(frame_num)

            if frame_num == self.num_frames - 1:
                frame_num = 0  #Start video over at end

            cv2.imshow(window_name, img)

        print(
            '\n'
        )  # Print blank line to remove progressbar if video was quit before ending

        cv2.destroyAllWindows()
Пример #2
0
    def save_video(self, playback_speed=15, realtime_framerate=4):
        """Save the video as a .avi file.

        Parameters
        ----------
        playback_speed : int, optional
            Multiple of realtime speed to playback video at.
        realtime_framerate : int, optional
            Number of frames taken by the thermal camera in real time.
        """

        framerate = playback_speed * realtime_framerate
        height = self.temp_data[0].shape[0] * self.scale_factor
        width = self.temp_data[0].shape[1] * self.scale_factor
        size = (width, height)
        filename = asksaveasfilename()

        video_writer = cv2.VideoWriter(
            filename, cv2.VideoWriter_fourcc('F', 'M', 'P', '4'), framerate,
            size)

        for i, frame in enumerate(self.temp_data):
            # Display completion percentage
            progress_bar.printProgressBar(i,
                                          self.num_frames,
                                          prefix='Saving Video...')

            img = self.generate_frame(i)

            video_writer.write(img)

        video_writer.release()
Пример #3
0
    def save_hotspot_video(self,
                           playback_speed=15,
                           realtime_framerate=4,
                           save_img=False):
        framerate = playback_speed * realtime_framerate
        height = self.temp_data[0].shape[0] * self.scale_factor
        width = self.temp_data[0].shape[1] * self.scale_factor
        size = (width, height)
        filename = asksaveasfilename()

        video_writer = cv2.VideoWriter(
            filename, cv2.VideoWriter_fourcc('F', 'M', 'P', '4'), framerate,
            size)

        hotspot_img = np.zeros((height, width), dtype=np.float32)

        for i, frame in enumerate(self.temp_data, 0):
            # Display completion percentage
            progress_bar.printProgressBar(
                i,
                self.num_frames,
                prefix='Saving Hotspot Video...',
            )

            current_max = np.amax(frame)
            current_max_y = np.where(frame == current_max)[0][0]
            current_max_x = np.where(frame == current_max)[1][0]

            hotspot_img[current_max_y, current_max_x] = current_max
            hotspot_img_frame = hotspot_img.copy()
            hotspot_img_frame = cv2.normalize(
                src=np.float32(hotspot_img_frame),
                dst=np.float32(hotspot_img_frame),
                alpha=0,
                beta=255,
                norm_type=cv2.NORM_MINMAX,
                dtype=cv2.CV_8UC1)
            hotspot_img_frame = cv2.applyColorMap(hotspot_img_frame,
                                                  cv2.COLORMAP_INFERNO)

            video_writer.write(hotspot_img_frame)

        video_writer.release()

        if save_img:
            cv2.imwrite('hotspot_img.png', hotspot_img_frame)
Пример #4
0
    def generate_video(self):
        """Load temperature and meltpool data, match them, and create the video array"""

        self.video_array = []

        if self.remove_bottom_reflection:
            lower_bounds = np_vid_viewer.reflection_remover.find_lower_bounds(
                self.temp_data)

        # Loop through each frame of data
        i = 0
        for frame in self.temp_data:
            frame = frame.copy()  # Make copy since file is read-only

            progress_bar.printProgressBar(i,
                                          self.num_frames,
                                          prefix='Generating Video...')

            if self.remove_top_reflection:
                np_vid_viewer.reflection_remover.remove_top(
                    frame, zero_level_threshold=180, max_temp_threshold=700)

            if self.remove_bottom_reflection:
                np_vid_viewer.reflection_remover.remove_bottom(
                    frame, lower_bounds)
            # Normalize the image to 8 bit color
            img = frame.copy()
            img = cv2.normalize(img, img, 0, 255, cv2.NORM_MINMAX, cv2.CV_8UC1)

            # Apply colormap to image
            img = cv2.applyColorMap(img, cv2.COLORMAP_INFERNO)

            # Add meltpool data onto the image
            if self.mp_data_on_vid:
                self.add_mp_data_to_img(img, i)

            # Add image to video array
            self.video_array.append(img)

            i = i + 1
Пример #5
0
    def generate_threshold_image(self, threshold=800):
        height = self.temp_data[0].shape[0] * self.scale_factor
        width = self.temp_data[0].shape[1] * self.scale_factor
        threshold_img = np.zeros((height, width), dtype=np.float32)
        for i, frame in enumerate(self.temp_data, 0):
            # Show progress
            progress_bar.printProgressBar(
                i, self.num_frames, prefix='Generating threshold image...')

            # Check each pixel, if pixel is over threshold, increment that pixel in theshold_img
            for y, row in enumerate(frame):
                for x, pixel in enumerate(row):
                    if pixel > threshold:
                        threshold_img[y, x] += 1

        threshold_img = cv2.normalize(src=threshold_img,
                                      dst=threshold_img,
                                      alpha=0,
                                      beta=255,
                                      norm_type=cv2.NORM_MINMAX,
                                      dtype=cv2.CV_8UC1)
        threshold_img = cv2.applyColorMap(threshold_img, cv2.COLORMAP_INFERNO)

        cv2.imwrite("threshold_img.png", threshold_img)