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

fix: bgr to rgb conversion inside frame_capturers #67

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))