google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.79k stars 5.18k forks source link

Check side of Pose in Javascript #2221

Closed Matokosp closed 3 years ago

Matokosp commented 3 years ago

Please make sure that this is a solution issue.

System information (Please provide as much relevant information as possible)

  • Have I written custom code (as opposed to using a stock example script provided in Mediapipe): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04, Android 11, iOS 14.4): React
  • MediaPipe version: MediaPipe.pose@0.3.1621277220
  • Bazel version:
  • Solution (e.g. FaceMesh, Pose, Holistic): Pose
  • Programming Language and version ( e.g. C++, Python, Java): Javascript

Describe the expected behavior: I'm trying to recognize which side of the person is facing the camera. Im using the z axis and each time I put a profile facing the camera it reaches 0 degrees, but I can't seem to work around a solution to distinguish which side it is (right or left profile)

Standalone code you may have used to try to get what you need :

let radians = Math.atan(results[23].x - results[11].x, results[23].z - results[11].z) - Math.atan(results[12].x - results[11].x, results[12].z - results[11].z) let angle = Math.abs(radians*180.0/Math.PI) if (angle > 180.0) { angle = 360-angle } let right_interest = [11,23] if (angle <= 1) { if (right_interest.forEach((e) => results[e].visibility < 0.7)) { console.log('right side') } }

If there is a problem, provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/repo link /any notebook:

Other info / Complete Logs : Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached:

tyrmullen commented 3 years ago

Pose should be returning estimated (x,y,z) locations for every canonical landmark in the person's body. It looks like you're using left-shoulder, right-shoulder, and left-hip keypoints if I'm reading the code correctly. I think there are quite a few directions you could go with this in terms of heuristics for "facing left", "facing right" or "facing straight ahead". Here's the first one I thought of, using those keypoints:

  • if left-shoulder is far left of the right-shoulder, then we say the person is facing forwards
  • if left-shoulder is far right of the right-shoulder, then we say the person is facing backwards
  • if left-shoulder and right-shoulder are somewhat near each other in the x-axis, then compare left-shoulder and right-shoulder .z to determine whether the person is facing left or right

This seems basically like what you're attempting to do above via the angle calculation-- but that might be making things a bit more complicated than necessary. For example, I'm not sure why you stop using the angle calculation and switch to using visibility. Also, one thing to note is that Math.atan limits resulting angles to [-pi/2, pi/2], so I think you probably want Math.atan2 instead, so you can map onto the entire circle.

google-ml-butler[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 3 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No