add toggle button for blueish cam fix (Force OpenCV2 BGR2RGB)

This commit is contained in:
underlines
2024-08-30 22:02:23 +02:00
parent 79c6615a68
commit c91ab8bbd2
5 changed files with 24 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
from typing import Any
import cv2
import modules.globals # Import the globals to check the color correction toggle
def get_video_frame(video_path: str, frame_number: int = 0) -> Any:
@@ -7,14 +8,16 @@ def get_video_frame(video_path: str, frame_number: int = 0) -> Any:
# Set MJPEG format to ensure correct color space handling
capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
# Force OpenCV to convert to RGB
capture.set(cv2.CAP_PROP_CONVERT_RGB, 1)
# Only force RGB conversion if color correction is enabled
if modules.globals.color_correction:
capture.set(cv2.CAP_PROP_CONVERT_RGB, 1)
frame_total = capture.get(cv2.CAP_PROP_FRAME_COUNT)
capture.set(cv2.CAP_PROP_POS_FRAMES, min(frame_total, frame_number - 1))
has_frame, frame = capture.read()
if has_frame:
if has_frame and modules.globals.color_correction:
# Convert the frame color if necessary
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)