简体   繁体   English

在检测到的面部上绘制 bitmap,将眼镜对准眼睛

[英]Drawing a bitmap on detected face, aligning glasses to the eyes

I'm learning face detection on Android using java.我正在使用 java 在 Android 上学习人脸检测。 I'm doing a tutorial where you draw sunglasses on a detected face.我正在做一个教程,你在检测到的脸上画太阳镜。 I have the faces and I'm able to draw the bitmap but the sunglasses aren't exactly aligned- they're close.我有脸,我可以画出 bitmap 但太阳镜没有完全对齐——它们很接近。 But more specifically where I'm getting held up is the tilting/rotating of the bitmap to match what I'm assuming should be the getHeadEulerAngleY() position from firebase vision faces.但更具体地说,我遇到的问题是 bitmap 的倾斜/旋转,以匹配我假设应该是来自 ZBF12E1515C25C3D8C0352F141 的 getHeadEulerAngleY() position 的内容。 I used a Matrix to try and "tilt" the glasses with the Y axis but the glasses only rotate in one direction- so not necessarily the eyes.我使用 Matrix 尝试用 Y 轴“倾斜”眼镜,但眼镜只向一个方向旋转——所以不一定是眼睛。 If it's a float I get from the head Euler Angle Y, wouldn't the negative bitmap rotation corrispond with the value of the float?如果它是我从头部欧拉角 Y 得到的浮点数,负 bitmap 旋转是否与浮点值相对应?

I'm also still very knew and trying to learn.我也仍然非常了解并努力学习。

many different answers got me to this point, but now I'm stuck.许多不同的答案让我走到了这一步,但现在我被困住了。

For example to aling with the eyes:以眼睛疲劳为例:

 if(leftEye != null && rightEye != null){
          distance = (float) Math.sqrt(
                        Math.pow(rightEye.getPosition().getX() - 
                        leftEye.getPosition().getX(), 2) +
                        Math.pow(rightEye.getPosition().getY() - 
                        leftEye.getPosition().getY(), 2)); 

rect = new Rect(
           Math.round(leftEye.getPosition().getX() - distance), 
           Math.round(leftEye.getPosition().getY() - distance), 
           Math.round(rightEye.getPosition().getX() + distance), 
           Math.round(rightEye.getPosition().getY() + distance));
 }else{
    rect = face.getBoundingBox;
}

this gets the glasses quite closly aligned with eyes.这使眼镜与眼睛非常紧密地对齐。

But what I attempted to do before that code executes was using a Matrix to turn the bitmap first, based on the Y axis:但是我在执行该代码之前尝试做的是使用矩阵首先基于 Y 轴转动 bitmap:

 Matrix matrix = new Matrix();
    matrix.postRotate(face.getHeadEulerAngleY);

then apply the glasses to the canvas
      canvas.drawBitmap(sunglasses, null, rect, null);
image.setImgBitmap(mutable)

I'm sure I'm missing something.我确定我错过了一些东西。 That glasses formula is from a similar function that got me closest to the eyes, so I'm guessing there's a similar one to match the axis.那个眼镜公式来自一个类似的 function 让我离眼睛最近,所以我猜有一个类似的来匹配轴。 I'm not sure where to start.我不知道从哪里开始。

Thanks for the help!谢谢您的帮助!

I think I got it.... It's crude and SO FAR seems to be working and you cant t tilt too far, but I guess you just want the opposite of the Z and Y axis.我想我明白了……它很粗糙,而且 SO FAR 似乎正在工作,你不能倾斜太远,但我想你只是想要 Z 轴和 Y 轴的相反方向。 As in you're turning the bitmap INTO the axis of the face or whatever.就像您将 bitmap 旋转到面轴或其他轴上一样。 Like a plane yoke.像飞机轭。

so-所以-

if(signum(face.Z) < 0) {如果(signum(face.Z)<0){

matrix.setRotate(Mathabs(faceZ); matrix.setRotate(Mathabs(faceZ);

}else if(signum(faceZ)>0{ }否则如果(signum(faceZ)>0{

matrix.setRotate(-faceZ);矩阵.setRotate(-faceZ);

}else{ setrotate(0) } }else{ setrotate(0) }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM