Skip to content

Commit 7fc9f87

Browse files
authored
Fix bgr-rgb conversion with sleap-render (#2444)
1 parent 1454e2e commit 7fc9f87

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sleap/io/visuals.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _mark_single_frame(self, video_frame: np.ndarray, frame_idx: int) -> np.ndar
158158
frame_idx: Index of frame in video.
159159
160160
Returns:
161-
ndarray of frame image with visual annotations added.
161+
ndarray of frame image with visual annotations added (in RGB format).
162162
"""
163163
# Use OpenCV to convert to BGR color image
164164
video_frame = img_to_cv(video_frame)
@@ -171,10 +171,16 @@ def _mark_single_frame(self, video_frame: np.ndarray, frame_idx: int) -> np.ndar
171171
self._crop_frame(video_frame.copy())[0] if self.crop else video_frame
172172
)
173173

174-
return cv2.addWeighted(
174+
result = cv2.addWeighted(
175175
overlay, self.alpha, video_frame_cropped, 1 - self.alpha, 0
176176
)
177177

178+
# Convert back to RGB for imageio/FFMPEG writes (which expect RGB, not BGR)
179+
if result.shape[-1] == 3:
180+
result = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
181+
182+
return result
183+
178184
def _plot_instances_cv(
179185
self,
180186
img: np.ndarray,

0 commit comments

Comments
 (0)