def run()

in src/open_vp_cal/framework/auto_roi.py [0:0]


    def run(self) -> AutoROIResults:
        """
        Run the auto roi detection

        Returns:
            AutoROIResults: The results of the roi detection
        """
        results = AutoROIResults()
        first_patch_frame, _ = self.calculate_first_and_last_patch_frame()

        if first_patch_frame > self.led_wall.sequence_loader.end_frame:
            return results

        frame = self.led_wall.sequence_loader.get_frame(
            first_patch_frame + self.trim_frames)

        image_plate_gamut = frame.image_buf
        pixel_buffer = 5
        detection_threshold = 1.7

        # Create the white balance matrix
        white_balance_matrix = self.get_white_balance_matrix_from_slate()

        # Ensure the image is in reference space (ACES2065-1)
        frame_image = imaging_utils.apply_color_conversion(
            image_plate_gamut,
            str(self.led_wall.input_plate_gamut),
            str(self.led_wall.project_settings.reference_gamut)
        )

        # Apply the white balance matrix to the frame
        balanced_image = imaging_utils.apply_matrix_to_img_buf(
            frame_image, white_balance_matrix
        )
        for y_pos in range(balanced_image.spec().height):
            for x_pos in range(balanced_image.spec().width):
                pixel = balanced_image.getpixel(x_pos, y_pos)
                red = clamp(pixel[0], 0, sys.float_info.max)
                green = clamp(pixel[1], 0, sys.float_info.max)
                blue = clamp(pixel[2], 0, sys.float_info.max)

                if red > results.red_value:
                    if red > max(green, blue) * detection_threshold:
                        results.red_pixel = (x_pos + pixel_buffer, y_pos + pixel_buffer)
                        results.red_value = red

                if green > results.green_value:
                    if green > max(red, blue) * detection_threshold:
                        results.green_pixel = (
                        x_pos - pixel_buffer, y_pos + pixel_buffer)
                        results.green_value = green

                if blue > results.blue_value:
                    if blue > max(red, green) * detection_threshold:
                        results.blue_pixel = (
                        x_pos + pixel_buffer, y_pos - pixel_buffer)
                        results.blue_value = blue

                white = (red + green + blue) / 3
                if white > results.white_value:
                    results.white_pixel = (x_pos - pixel_buffer, y_pos - pixel_buffer)
                    results.white_value = white
        return results