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

feat: added abstract class for FrameCapturer #44

Merged
merged 1 commit into from
Sep 12, 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
32 changes: 32 additions & 0 deletions client/models/pose_detection/frame_capturer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from abc import ABC, abstractmethod

import numpy as np
import cv2


class FrameCapturer(ABC):
"""Provides an interface to video frames for a PostureTracker."""

@abstractmethod
def get_frame(self) -> tuple[np.ndarray, int]:
"""
Returns:
(frame, timestamp), image is an image frame in the format HxWxC. Where the channels are
in RGB format. Timestamp is in milliseconds.
LimaoC marked this conversation as resolved.
Show resolved Hide resolved
"""


class OpenCVCapturer(FrameCapturer):
"""FrameCapturer using OpenCV to read from camera."""

def __init__(self) -> None:
self._cam = cv2.VideoCapture(0)

def get_frame(self) -> tuple[np.ndarray, int]:
_, frame = self._cam.read()
timestamp = self._cam.get(cv2.CAP_PROP_POS_MSEC)
return frame, timestamp

def release(self) -> None:
"""Release the camera."""
self._cam.release()