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 #29 from LimaoC/mitch-doc-attr
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellJC authored Aug 19, 2024
2 parents 7059e2a + 01ecae3 commit 7aa3853
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
22 changes: 18 additions & 4 deletions client/data/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@


class User(NamedTuple):
"""Represents a user record in the SQLite database"""
"""Represents a user record in the SQLite database
Attributes:
id_: Unique id for the user. Should be set to None when user does not exist in DB.
"""

id_: Optional[int]


class Posture(NamedTuple):
"""Represents a posture record in the SQLite database"""
"""Represents a posture record in the SQLite database
Attributes:
id_: Unique id for the posture record. Should be set to None when record does not exist in
DB.
user_id: The user for which this posture applies to.
prop_good: Proportion of time the user is in the frame which the posture is good.
prop_in_frame: Proportion of time the user is in the frame during the period.
period_start: Start of the tracked period.
period_end: End of the tracked period.
"""

id_: Optional[int]
user_id: int
Expand Down Expand Up @@ -85,7 +99,7 @@ def get_users(num: int = 10) -> list[User]:
"""
Args:
num: Number of user to retrieve
Returns:
num users from the database.
"""
Expand All @@ -99,7 +113,7 @@ def get_postures(num: int = 10) -> list[Posture]:
"""
Args:
num: Number of posture records to retrieve
Returns:
num posture records from the database.
"""
Expand Down
5 changes: 4 additions & 1 deletion client/models/pose_detection/landmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

@dataclass
class AnnotatedImage:
"""Represents mutable annotated image through data attribute.
"""Represents mutable annotated image container.
Can be used to set annotated image within a callback asynchronously without raising
an error.
Attributes:
data: The actual image.
"""

data: Optional[np.ndarray] = None
Expand Down
14 changes: 9 additions & 5 deletions client/models/pose_detection/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@


class DebugPostureTracker(PoseLandmarker):
"""Handles routines for a Debugging Posture Tracker"""
"""Handles routines for a Debugging Posture Tracker.
Attributes:
annotated_image: Mutable container for an image which may be mutated asynchronously.
"""

def __init__(
self,
Expand All @@ -35,17 +39,17 @@ def __init__(
) -> None:
super().__init__(graph_config, running_mode, packet_callback)
self.annotated_image = AnnotatedImage()
self.video_capture = cv2.VideoCapture(0)
self._video_capture = cv2.VideoCapture(0)

def track_posture(self) -> None:
"""Get frame from video capture device and process with pose model, then posture
algorithm. Print debugging info and display landmark annotated frame.
"""
success, frame = self.video_capture.read()
success, frame = self._video_capture.read()
if not success:
return

frame_timestamp_ms = self.video_capture.get(cv2.CAP_PROP_POS_MSEC)
frame_timestamp_ms = self._video_capture.get(cv2.CAP_PROP_POS_MSEC)
mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)
self.detect_async(mp_image, int(frame_timestamp_ms))

Expand All @@ -54,7 +58,7 @@ def track_posture(self) -> None:
cv2.imshow("output", self.annotated_image.data)

def __exit__(self, unused_exc_type, unused_exc_value, unused_traceback) -> None:
self.video_capture.release()
self._video_capture.release()
cv2.destroyAllWindows()
super().__exit__(unused_exc_type, unused_exc_value, unused_traceback)

Expand Down

0 comments on commit 7aa3853

Please sign in to comment.