Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #67 from LimaoC/mitch-rgb-fix
Browse files Browse the repository at this point in the history
fix: bgr to rgb conversion inside frame_capturers
  • Loading branch information
MitchellJC authored Oct 2, 2024
2 parents 866e56f + 6b88c5d commit 5d1064d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/models/pose_detection/frame_capturer.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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."""
Expand All @@ -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)
finfo = os.stat("/tmp/snapshot.jpg")
return (array, int(finfo.st_mtime))

0 comments on commit 5d1064d

Please sign in to comment.