From 9d00ec0d1d324f191311aa08f79f00c4f83a115d Mon Sep 17 00:00:00 2001 From: Mayank Singh Date: Wed, 8 Jan 2025 21:07:42 +0530 Subject: [PATCH] Added pose_estimation.py with real-time 3D pose estimation code --- pose_estimation.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pose_estimation.py diff --git a/pose_estimation.py b/pose_estimation.py new file mode 100644 index 0000000..401a25e --- /dev/null +++ b/pose_estimation.py @@ -0,0 +1,35 @@ + +### 3. **Add Comments in Code** + +Adding comments in your code can help explain complex sections and improve readability. + +**Example:** +```python +while cap.isOpened(): + ret, frame = cap.read() + if not ret: + break + + # Convert the frame to RGB (required by Mediapipe) + frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + + # Process the frame to obtain pose landmarks + results = pose_detector.process(frame_rgb) + + # Draw landmarks on the frame (optional for visualization) + draw_landmarks_on_image(frame, results) + + # Extract 3D landmarks + landmark_positions_3d = read_landmark_positions_3d(results) + if landmark_positions_3d is not None: + # Send landmark positions to Unity via UDP + data = json.dumps(landmark_positions_3d.tolist()) # Convert to JSON format + sock.sendto(data.encode('utf-8'), server_address) # Send data to Unity + print(f'3D Landmarks: {landmark_positions_3d}') # Optional: Print landmarks to console + + # Display the frame with landmarks drawn + cv2.imshow('Real-Time 3D Pose Estimation', frame) + + # Exit loop when 'q' key is pressed + if cv2.waitKey(1) & 0xFF == ord('q'): + break