deeprehab-visualize
Visualization functions for DeepRehab pose data and analysis results.
Installation
pip install deeprehab-visualize
Usage
Basic Example
import cv2
from deeprehab_visualize import (
draw_landmarks_on_frame,
visualize_angles_on_frame,
visualize_score_on_frame,
create_pose_connections
)
# Load a video frame
frame = cv2.imread("frame.jpg")
# Assume you have landmarks from deeprehab-pose
landmarks = extract_landmarks("video.mp4")[0] # First frame landmarks
# Draw landmarks on frame
connections = create_pose_connections()
annotated_frame = draw_landmarks_on_frame(frame, landmarks, connections)
# Visualize angles (assuming you have angle data from deeprehab-angles)
angles = {"left_knee": 90.5, "right_knee": 89.2}
annotated_frame = visualize_angles_on_frame(annotated_frame, landmarks, angles)
# Visualize score (assuming you have score data from deeprehab-movements)
score_result = score_deep_squat(landmarks) # Example scoring function
annotated_frame = visualize_score_on_frame(annotated_frame, score_result)
# Save or display the annotated frame
cv2.imwrite("annotated_frame.jpg", annotated_frame)
Functions
draw_landmarks_on_frame(frame, landmarks, connections=None)
Draw pose landmarks on a video frame.
Parameters:
frame: Video frame as numpy array (H, W, C)landmarks: List of landmark objects with x, y, z, visibility attributesconnections: List of tuples defining connections between landmarks
Returns:
- Frame with landmarks drawn on it
visualize_angles_on_frame(frame, landmarks, angles, position=(50, 50))
Visualize angle measurements on a video frame.
Parameters:
frame: Video frame as numpy array (H, W, C)landmarks: List of landmark objectsangles: Dictionary of angle measurements (e.g., {'left_knee': 90.0})position: Position to display text (x, y)
Returns:
- Frame with angle measurements displayed
visualize_score_on_frame(frame, score_result, position=(50, 150))
Visualize FMS score on a video frame.
Parameters:
frame: Video frame as numpy array (H, W, C)score_result: ScoreResult object with score, reason, and detailsposition: Position to display text (x, y)
Returns:
- Frame with score displayed
create_pose_connections()
Create standard pose connections for visualization.
Returns:
- List of tuples representing connections between landmarks
Integration with Other DeepRehab Packages
from deeprehab_pose import extract_landmarks
from deeprehab_angles import knee_angle
from deeprehab_movements import score_deep_squat
from deeprehab_visualize import (
draw_landmarks_on_frame,
visualize_angles_on_frame,
visualize_score_on_frame,
create_pose_connections
)
import cv2
# Extract pose landmarks
landmarks_list = extract_landmarks("squat_video.mp4")
# Process each frame
for i, landmarks in enumerate(landmarks_list):
# Read the corresponding frame
cap = cv2.VideoCapture("squat_video.mp4")
for _ in range(i):
cap.read()
ret, frame = cap.read()
if ret:
# Draw pose landmarks
connections = create_pose_connections()
annotated_frame = draw_landmarks_on_frame(frame, landmarks, connections)
# Calculate angles
left_knee = knee_angle(landmarks, "left")
right_knee = knee_angle(landmarks, "right")
angles = {"left_knee": left_knee, "right_knee": right_knee}
annotated_frame = visualize_angles_on_frame(annotated_frame, landmarks, angles)
# Score movement
score_result = score_deep_squat(landmarks)
annotated_frame = visualize_score_on_frame(annotated_frame, score_result)
# Save annotated frame
cv2.imwrite(f"annotated_frame_{i}.jpg", annotated_frame)
License
MIT
Metadata
Release files for deeprehab-visualize 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| deeprehab_visualize-0.1.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deeprehab_visualize-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / deeprehab_visualize-0.1.0.tar.gz
| Download URL | deeprehab_visualize-0.1.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96c04e71956c5e50e30d576a03ee1e69f33bc4449457257f5f22d6409d393837
|
|
BLAKE2b-256 checksum How to use checksums |
9b94a7f6c547d1199613be54ef087a50d874c77344df9c9ecfddd5bad81a3ab0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / deeprehab_visualize-0.1.0-py3-none-any.whl
| Download URL | deeprehab_visualize-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84948763dc8d5744d566dfcdc359b08fe339fc50e9306f84d5787caeac7e065d
|
|
BLAKE2b-256 checksum How to use checksums |
648b4c3a25fe2bf479fd45691d986f010ef40cc61072a63bf93f24680afa4d71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|