jeeliz / jeelizWeboji

JavaScript/WebGL real-time face tracking and expression detection library. Build your own emoticons animated in real time in the browser! SVG and THREE.js integration demos are provided.
https://jeeliz.com
Apache License 2.0
1.07k stars 149 forks source link

Get coordinates of the face #8

Closed sonidiaz closed 5 years ago

sonidiaz commented 5 years ago

Hi, guys, me again In the app that I am working I need to get a picture of the face for each gesture that the user makes. For that I need to get the data of the x, y, width and height coordinates like jeelizFaceFilter does with detectState. I saw that they added the method get_positionScale() (https://github.com/jeeliz/jeelizWeboji/issues/5) but I can not get the data correctly and I do not know if it will help me for what I need. Could you tell me if that is the way to go to get that data (x, y, w, h) with JEEFACETRANSFERAPI?

Thank you!

xavierjs commented 5 years ago

With positionScale you got Px,Py,s relative to the viewport To get x,y,w,h in pixels you have: x = W(Px+1)/2 y = H(Py+1)/2 w = W*s h = w (because the face detection is a square) W,H are the size of the viewport in pixels. x,y are the coordinates of the center of the detection window (not the corner).

sonidiaz commented 5 years ago

Thanks for the quick reply! I will review that function.

sonidiaz commented 5 years ago

Hi @xavierjs,

Sorry to bother you, but I can't get the data correctly, I'm probably doing something wrong, but with the data I get I can't do much. Do you have an example of how to apply it?

Thanks and sorry again!

xavierjs commented 5 years ago

Hi,

I did a mistake, I correct it and commit the changes, it should be working now :) I also updated the documentation. x and y are given between 0 and 1 Only 3 floats are returned by get_positionScale. Indeed since the detection window is a square we don't need the scale along the vertical axis. It also allows me to detect and correct a bug relative to stabilization :).

xavierjs commented 5 years ago

To resume, To get x,y,w,h in pixels you have: x = WPx y = HPy w = W*s h = w (because the face detection is a square) W,H are the size of the viewport in pixels. x,y are the coordinates of the center of the detection window (not the corner).

sonidiaz commented 5 years ago

Hi, @xavierjs Yea!!! Now it works very well and the stabilization has improved a lot. Thank you!