Skip to content

Commit 9d00ec0

Browse files
committed
Added pose_estimation.py with real-time 3D pose estimation code
1 parent 9eb2644 commit 9d00ec0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pose_estimation.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
### 3. **Add Comments in Code**
3+
4+
Adding comments in your code can help explain complex sections and improve readability.
5+
6+
**Example:**
7+
```python
8+
while cap.isOpened():
9+
ret, frame = cap.read()
10+
if not ret:
11+
break
12+
13+
# Convert the frame to RGB (required by Mediapipe)
14+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
15+
16+
# Process the frame to obtain pose landmarks
17+
results = pose_detector.process(frame_rgb)
18+
19+
# Draw landmarks on the frame (optional for visualization)
20+
draw_landmarks_on_image(frame, results)
21+
22+
# Extract 3D landmarks
23+
landmark_positions_3d = read_landmark_positions_3d(results)
24+
if landmark_positions_3d is not None:
25+
# Send landmark positions to Unity via UDP
26+
data = json.dumps(landmark_positions_3d.tolist()) # Convert to JSON format
27+
sock.sendto(data.encode('utf-8'), server_address) # Send data to Unity
28+
print(f'3D Landmarks: {landmark_positions_3d}') # Optional: Print landmarks to console
29+
30+
# Display the frame with landmarks drawn
31+
cv2.imshow('Real-Time 3D Pose Estimation', frame)
32+
33+
# Exit loop when 'q' key is pressed
34+
if cv2.waitKey(1) & 0xFF == ord('q'):
35+
break

0 commit comments

Comments
 (0)