Skip to content

Added pose_estimation.py with real-time 3D pose estimation code #26

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pose_estimation.py
Original file line number Diff line number Diff line change
@@ -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
Loading