tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Feature request to include face rotation in facemesh

Open n0noob opened this issue 5 years ago • 16 comments
trafficstars

To get help from the community, we encourage using Stack Overflow and the tensorflow.js tag.

TensorFlow.js version

NA

Browser version

NA

Describe the problem or feature request

Currently facemesh detection results include only 468 landmark points. Wouldn't it be better to include face rotation as well in the detection results ?

Code to reproduce the bug / link to feature request

If you would like to get help from the community, we encourage using Stack Overflow and the tensorflow.js tag.

GitHub issues for this repository are tracked in the tfjs union repository.

Please file your issue there, following the guidance in that issue template.

n0noob avatar Aug 20 '20 18:08 n0noob

@n0noob you mean like tilting your head some degree to the left/right? If yes, you can calculate it by yourself. Something like this.

const predictions = await model.estimateFaces(video);

if (predictions.length > 0) {
  const { annotations } = predictions[0];

  const [topX, topY] = annotations['midwayBetweenEyes'][0];

  const [rightX, rightY] = annotations['rightCheek'][0];
  const [leftX, leftY] = annotations['leftCheek'][0];
  const bottomX = (rightX + leftX) / 2;
  const bottomY = (rightY + leftY) / 2;

  const degree = Math.atan((topY - bottomY) / (topX - bottomX));

  console.log(degree);
}

Disclaimer: I didn't test the code above but you can fiddle around with which annotations to use and more precise way to calculate the degree of rotation.

dikatok avatar Sep 01 '20 12:09 dikatok

I think what he meant was to include the pitch, yaw and roll angles - Aircraft_principal_axes.

It would be an interesting addition and would bring more possibilities for using the model.

DamascenoRafael avatar Dec 07 '20 20:12 DamascenoRafael

@DamascenoRafael Yes, thank you, this is what I meant.

n0noob avatar Dec 20 '20 17:12 n0noob

Any idea on how I can calculate the Yaw of the facemesh assuming I was to look at it from the front?

rgs2151 avatar Jan 22 '21 05:01 rgs2151

Hi @wakoan - I think we discussed this at some point - and you showed me your team's solution to this problem. Would you mind transferring context to @lina128 ? Thank you!

annxingyuan avatar Mar 02 '21 15:03 annxingyuan

@n0noob Use this code for x and y rotations i am using this for liveness detection:

getHeadAnglesCos(keypoints) { // V: 10, 152; H: 226, 446 this.faceVerticalCentralPoint = [ 0, (keypoints[10][1] + keypoints[152][1]) * 0.5, (keypoints[10][2] + keypoints[152][2]) * 0.5, ]; const verticalAdjacent = keypoints[10][2] - this.faceVerticalCentralPoint[2]; const verticalOpposite = keypoints[10][1] - this.faceVerticalCentralPoint[1]; const verticalHypotenuse = this.l2Norm([ verticalAdjacent, verticalOpposite, ]); const verticalCos = verticalAdjacent / verticalHypotenuse;

this.faceHorizontalCentralPoint = [
  (keypoints[226][0] + keypoints[446][0]) * 0.5,
  0,
  (keypoints[226][2] + keypoints[446][2]) * 0.5,
];
const horizontalAdjacent =
        keypoints[226][2] - this.faceHorizontalCentralPoint[2];
const horizontalOpposite =
        keypoints[226][0] - this.faceHorizontalCentralPoint[0];
const horizontalHypotenuse = this.l2Norm([
  horizontalAdjacent,
  horizontalOpposite,
]);
const horizontalCos = horizontalAdjacent / horizontalHypotenuse;

return [
  verticalCos,
  horizontalCos,
];

}

l2Norm(vec) { let norm = 0; for (const v of vec) { norm += v * v; } return Math.sqrt(norm); }

akhirai560 avatar Mar 08 '21 05:03 akhirai560

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

google-ml-butler[bot] avatar Mar 15 '21 22:03 google-ml-butler[bot]

It is still an interesting feature to be implemented

DamascenoRafael avatar Mar 16 '21 17:03 DamascenoRafael

I will follow up with @wakoan on this feature.

lina128 avatar Mar 18 '21 01:03 lina128

@n0noob Are you sure rotation angles are really needed? Maybe rotation matrix 3x3 will be enough?

For face mesh, it is trivial to find rot matrix: there are points on left/right cheeks that define "x", points on bottom of mesh and top that define "y", their cross product is "z". Normalize each vector and R = [ x_n y_n z_n ].

latex

Obtaining Euler angles (roll, pitch, yaw) from rotation matrix is doable, but has disadvantages like gimbal lock.

Sinthanayothin et al. "Morph targets for 3D facial animation ..." (link) use this idea: 00078_PSISDG11878_1187820_page_3_5

AlexShafir avatar Oct 15 '21 08:10 AlexShafir

@lina128 I have opened corresponding MR in tfjs-models.

AlexShafir avatar Oct 19 '21 09:10 AlexShafir

Hi @n0noob and @AlexShafir, we are working on providing the rotating feature to face-landmark API. It will likely be launched in January. I'm adding the engineer who will be working on it. In the meantime, feel free to patch the solutions the community provides here.

lina128 avatar Nov 03 '21 18:11 lina128

@lina128 are contributions still welcome or "stat:contributions welcome" label should be removed?

AlexShafir avatar Nov 03 '21 19:11 AlexShafir

Facemesh is deprecated , please try our latest face-detection model which has support included for "rotated faces". Thank you

rthadur avatar Apr 20 '22 15:04 rthadur

@rthadur How to access that "rotated faces" feature?

akssieg avatar Apr 22 '22 23:04 akssieg

We are still working on an accurate approach to get the transformation for face. Stay tuned.

lina128 avatar Apr 25 '22 22:04 lina128

any update on this?

gauravmankotia avatar Mar 01 '23 12:03 gauravmankotia

We are still working on an accurate approach to get the transformation for face. Stay tuned.

Any update on this?

parth7326 avatar Mar 24 '23 08:03 parth7326

Hi, @n0noob

Apologize for the delayed response and @tensorflow-models/facemesh , that package has been archived in favor of @tensorflow-models/face-landmarks-detection and will no longer be updated. you can refer here. Please go with @tensorflow-models/face-landmarks-detection.

If you face any issues with Face Landmarks Detection, Please let us know ? Thank you!

gaikwadrahul8 avatar Jun 20 '23 08:06 gaikwadrahul8

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Jun 28 '23 02:06 github-actions[bot]

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] avatar Jul 06 '23 02:07 github-actions[bot]