Skip to content

Commit

Permalink
Fix: Convert BGR to RGB color space for correct video colors (#338)
Browse files Browse the repository at this point in the history
- Added cv2.cvtColor conversion before PIL processing
- Fixes blue tint issue in video feed
- Ensures correct color representation in Gemini 2.0 Live API video feed
- Added explanatory comments for future maintainers

Issue: Video feed shows blue tint due to BGR/RGB colorspace mismatch
Solution: Convert OpenCV BGR output to RGB before PIL processing
  • Loading branch information
robotlovehuman authored Dec 12, 2024
1 parent c1c5c69 commit 67633d3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gemini-2/websockets/live_api_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def _get_frame(self, cap):
if not ret:
return None

img = PIL.Image.fromarray(frame)
# Fix: Convert BGR to RGB color space
# OpenCV captures in BGR but PIL expects RGB format
# This prevents the blue tint in the video feed
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = PIL.Image.fromarray(frame_rgb) # Now using RGB frame
img.thumbnail([1024, 1024])

image_io = io.BytesIO()
Expand Down

0 comments on commit 67633d3

Please sign in to comment.