gpt4 book ai didi

Android 人脸检测 MaxNumDetectedFaces

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:13:56 26 4
gpt4 key购买 nike

所以我刚刚将我的平板电脑(原华硕变形金刚)升级到安卓版本 4.0.3 以构建一个使用人脸检测的应用程序。但是每次我启动它并尝试开始人脸检测时,我都会在 logcat 中收到此错误:

E/AndroidRuntime(1755): java.lang.IllegalArgumentException: invalid face detection type=0

我在文档中读到这意味着可以检测到或支持 0 张面孔,但这是否意味着我的设备根本无法检测到面孔,或者我可以更改吗?另外它使用后置摄像头,将其更改为另一个摄像头会改变什么吗?我一直在尝试这样做,但我无法弄清楚如何,可以在此处找到我尝试运行的项目:

https://docs.google.com/open?id=0B2Nu5U2Cz81qZExGQ25sWVdRd21IOExUUTZsZzFoZw

来自这个 SO 问题: Android face detector using android camera

最佳答案

请记住,您可以使用较旧的 FaceDetector API 检测人脸.它从 API 级别 1 开始就存在,应该可以在所有带摄像头的手机上使用。它还会在检测到人脸时返回一个边界框。

public Rect findFace(Bitmap bmp) {
// Ask for 1 face
Face faces[] = new FaceDetector.Face[1];
FaceDetector detector = new FaceDetector( bmp.getWidth(), bmp.getHeight(), 1 );
int count = detector.findFaces( bmp, faces );

Face face = null;

if( count > 0 ) {
face = faces[0];

PointF midEyes = new PointF();
face.getMidPoint( midEyes );
Log.i( TAG,
"Found face. Confidence: " + face.confidence() + ". Eye Distance: " + face.eyesDistance() + " Pose: ("
+ face.pose( FaceDetector.Face.EULER_X ) + "," + face.pose( FaceDetector.Face.EULER_Y ) + ","
+ face.pose( FaceDetector.Face.EULER_Z ) + "). Eye Midpoint: (" + midEyes.x + "," + midEyes.y + ")" );

float eyedist = face.eyesDistance();
PointF lt = new PointF( midEyes.x - eyedist * 2.0f, midEyes.y - eyedist * 2.5f );
// Create rectangle around face. Create a box based on the eyes and add some padding.
// The ratio of head height to width is generally 9/5 but that makes the rect a bit to tall.
return new Rect(
Math.max( (int) ( lt.x ), 0 ),
Math.max( (int) ( lt.y ), 0 ),
Math.min( (int) ( lt.x + eyedist * 4.0f ), bmp.getWidth() ),
Math.min( (int) ( lt.y + eyedist * 5.5f ), bmp.getHeight() )
);
}

return null;
}

关于Android 人脸检测 MaxNumDetectedFaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9578097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com