Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

How to convert mediapipe coordinates into Unity world space coordinates? #676

Closed
BoneFlat opened this issue May 3, 2020 · 21 comments
Closed
Labels
platform:unity MediaPipe Unity issues

Comments

@BoneFlat
Copy link

BoneFlat commented May 3, 2020

Hi MediaPipe Team, i'm trying to convert 21 landmarks into unity 3d world space.
I follow these step to do that:
Step 1: I follow @eknight7 instruction from #454 to get NormalizedRect in image coordinates.
Step 2: Because "NormalizedLandmark" is landmark location in HandRect coordinates, so i can convert 21 point into image coordinates.
Step 3: I'm using "ScreenToWorldSpace" method in Unity to convert 21 point in image coordinate to 3d world space with a specifi depth (depth = 3 in my case).

But the final result in Unity has a little discrepancies , you can see in image below.
Can you give me some advise to convert the landmarks. And i also want to know is there a solution to get the real depth?

Screenshot_20200503-200241_AR Single

@CalebGreer
Copy link

I have been trying to use mediapipe with Unity as well and was wondering do you have mediapipe running within Unity or are you getting the landmarks somewhere else and then sending it to Unity?

@BoneFlat
Copy link
Author

BoneFlat commented May 3, 2020

@CalebGreer, i'm building aar (android archive library) and use it as plugin for Unity

@CalebGreer
Copy link

@BoneFlat Oh, I had tried that but couldn't get it to work. Would you mind sharing your solution or how you got the aar to work within Unity?

@BoneFlat
Copy link
Author

BoneFlat commented May 6, 2020

@CalebGreer, i'm following "the left" solution at #36 (comment).
For plugin, I'm using 2 aar plugin , one is mediapipe aar we have build, another is wrote to hold some method like "InitGraph, StartGraph, SetInputBitmap, GetLandMark ...".
In Unity, i get texture from webcamtexture, convert it to byte array and use byte array for plugin's input

@BoneFlat
Copy link
Author

BoneFlat commented May 7, 2020

Now, i'm ok with x and y in image coordinates but with the depth, i still have no idea

@SwatiModi
Copy link

Hey @BoneFlat,
Can you tell more about the another AAR you used with InitGraph, StartGraph functions? I checked out FrameProcessor.java but unable to understand how to use it with the byte array input to mediapipe from unity.

@justinduynguyen
Copy link

i'm considering that how to stream a byte array from unity webcam to mediapipe ? Any solution? Thank you.

@brianm-sra
Copy link

@BoneFlat did you make any progress on this?

@BoneFlat
Copy link
Author

BoneFlat commented Jun 15, 2020

Sorry all for the late answer, i made a simple project that show how to use mediapipe with Unity, i also made a unity package, you can use this for another project. You can found all here: https://gitlab.com/thangnh.sas/mediapipe-unity-hand-tracking

@JackieNek
Copy link

I made a solution to solve the depth and made a simple game base on that here: https://gitlab.com/JackieNek/single-hand-tracking . You can see demo here: https://youtu.be/paZ3sXtKTq8

@brianm-sra
Copy link

@BoneFlat : in your ARHand.cs file I found this code:
for (int i = 0; i < 21; i++) {
float xScreen = Screen.width * ((arr[i * 3 + 1] - 0.5f * (1 - c)) / c);
float yScreen = Screen.height * (arr[i * 3]);
this.landmarks[i] = cam.ScreenToWorldPoint(new Vector3(xScreen, yScreen, arr[i * 3 + 2] / 80 + 0.4f));
}

Would you be willing to share how you determined that those formulas were correct?
In particular for X and Z

X - 0.5f * (1 - c)) / c
Z / 80 + 0.4f

Were these specific to camera calibration on your particular camera device ?

@justinduynguyen
Copy link

Thank you in advance guys.

@TheBricktop
Copy link

TheBricktop commented Jun 18, 2020

is it possible to build analogically build the media pipe as a
plugin for unity desktop?

@tutu5110
Copy link

All very cool! @BoneFlat

@sachinjambhulkar
Copy link

@BoneFlat Thank you ! The package is working like a charm. The only drag i have seen in FPS... i feel this has to be taken up to run over the GPU for better performance.

@danieljtrujillo
Copy link

@sachinjambhulkar could you describe in detail how you implemented it?

@sachinjambhulkar
Copy link

@danieljtrujillo clone the repo: https://gitlab.com/thangnh.sas/mediapipe-unity-hand-tracking. navigate to the base directory of this project, right click over the file "MediapipeUnityPackage.unitypackage" and open with the Unity.

You can observe the complete project with all assets getting imported to unity Editor. Open the SampleScene.unity and you can make it run on your preferred platform / end device target.

@mgyong mgyong closed this as completed Sep 22, 2020
@zhouwei5113
Copy link

@BoneFlat : in your ARHand.cs file I found this code:
for (int i = 0; i < 21; i++) {
float xScreen = Screen.width * ((arr[i * 3 + 1] - 0.5f * (1 - c)) / c);
float yScreen = Screen.height * (arr[i * 3]);
this.landmarks[i] = cam.ScreenToWorldPoint(new Vector3(xScreen, yScreen, arr[i * 3 + 2] / 80 + 0.4f));
}

Would you be willing to share how you determined that those formulas were correct?
In particular for X and Z

X - 0.5f * (1 - c)) / c
Z / 80 + 0.4f

Were these specific to camera calibration on your particular camera device ?

@brianm-sra Do you have any ideas about the formula?

@mcclanahoochie mcclanahoochie added the platform:unity MediaPipe Unity issues label Dec 8, 2020
@AlanWuJinliang
Copy link

@JackieNek @BoneFlat do you know why i cant show the hand bone in my android phone?

@AlanWuJinliang
Copy link

@BoneFlat Thank you ! The package is working like a charm. The only drag i have seen in FPS... i feel this has to be taken up to run over the GPU for better performance.

are you sure this demo can show hand bone?

@mostafamdy
Copy link

@BoneFlat Hi thanks for this package its great
but I have a problem on it. it works with 5 fps
so how can I make this package work on GPU to be faster or did you have another package that can work on GPU?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:unity MediaPipe Unity issues
Projects
None yet
Development

No branches or pull requests