File size: 1,041 Bytes
1ca9b28 cfbaa51 1ca9b28 4cdc77a 1ca9b28 89a012c 1ca9b28 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import numpy as np
from CPR_Module.Common.keypoints import CocoKeypoints
from CPR_Module.Common.logging_config import cpr_logger
class ShouldersAnalyzer:
"""Calculate and store shoulder distance for CPR rescuer"""
def __init__(self):
self.shoulder_distance = None
self.shoulder_distance_history = []
def calculate_shoulder_distance(self, rescuer_keypoints):
"""Calculate and store shoulder distance"""
if rescuer_keypoints is None:
return
try:
left = rescuer_keypoints[CocoKeypoints.LEFT_SHOULDER.value]
right = rescuer_keypoints[CocoKeypoints.RIGHT_SHOULDER.value]
distance = np.linalg.norm(np.array(left) - np.array(right))
return distance
except Exception as e:
cpr_logger.error(f"Shoulder distance error: {e}")
return
def reset_shoulder_distances(self):
"""Reset shoulder distances"""
self.shoulder_distance_history = []
|