Untitled
unknown
python
a year ago
1.4 kB
8
Indexable
@socketio.on('image_squat')
def handle_squat_image(data):
global squat_counter, squat_stage, squat_tips
img_data = data['image']
img_data = base64.b64decode(img_data)
nparr = np.frombuffer(img_data, dtype=np.uint8)
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
if results.pose_landmarks:
landmarks = results.pose_landmarks.landmark
l_hip = [landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].x * image.shape[1],
landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].y * image.shape[0]]
l_knee = [landmarks[mp_pose.PoseLandmark.LEFT_KNEE.value].x * image.shape[1],
landmarks[mp_pose.PoseLandmark.LEFT_KNEE.value].y * image.shape[0]]
l_ankle = [landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value].x * image.shape[1],
landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value].y * image.shape[0]]
l_angle = calculate_angle(l_hip, l_knee, l_ankle)
update_stage_and_counter_squat(l_angle, 'left')
draw_annotations_squat(image, results, l_angle)
_, buffer = cv2.imencode('.jpg', image)
response_image = base64.b64encode(buffer).decode('utf-8')
emit('response', {'image': response_image, 'data': {
'reps': squat_counter,
'stage': squat_stage
}})Editor is loading...
Leave a Comment