From 6b88c5d8db5b106b39ecc83b7fa2d3acdc774185 Mon Sep 17 00:00:00 2001 From: Mitchell Clark Date: Tue, 1 Oct 2024 23:39:26 +1000 Subject: [PATCH] fix: bgr to rgb conversion inside frame_capturers --- .../models/pose_detection/frame_capturer.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/client/models/pose_detection/frame_capturer.py b/client/models/pose_detection/frame_capturer.py index f32fd35..41247f9 100644 --- a/client/models/pose_detection/frame_capturer.py +++ b/client/models/pose_detection/frame_capturer.py @@ -1,9 +1,9 @@ +import time +import os from abc import ABC, abstractmethod import numpy as np -import time import cv2 -import os class FrameCapturer(ABC): @@ -26,8 +26,9 @@ def __init__(self) -> None: def get_frame(self) -> tuple[np.ndarray, int]: _, frame = self._cam.read() + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) timestamp = self._cam.get(cv2.CAP_PROP_POS_MSEC) - return frame, timestamp + return frame, int(timestamp) def release(self) -> None: """Release the camera.""" @@ -37,15 +38,18 @@ def release(self) -> None: class RaspCapturer(FrameCapturer): """FrameCapturer using a temp file to read from the camera. File is created using client/drivers/camera_overlord.py""" + def get_frame(self) -> tuple[np.ndarray, int]: tries = 0 while True: - array = cv2.imread('/tmp/snapshot.jpg') + array = cv2.imread("/tmp/snapshot.jpg") + array = cv2.cvtColor(array, cv2.COLOR_BGR2RGB) if array is None: tries += 1 - if tries > 5: raise FileNotFoundError('No snapshot found') - time.sleep(0.05) + if tries > 5: + raise FileNotFoundError("No snapshot found") + time.sleep(0.05) else: tries = 0 - finfo = os.stat('/tmp/snapshot.jpg') - return (array, finfo.st_mtime) \ No newline at end of file + finfo = os.stat("/tmp/snapshot.jpg") + return (array, int(finfo.st_mtime))