简体   繁体   English

Android FaceDetector.findFaces找不到任何面孔

[英]Android FaceDetector.findFaces doesn't find any faces

This is a code I have written to run android's face detector. 这是我编写的用于运行android的面部检测器的代码。 Unfortunately, it doesn't find any. 不幸的是,它找不到任何东西。 I have put this in a onPreviewFrame(data, camera). 我把它放在onPreviewFrame(数据,相机)中。

Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null);
Rect rectangle = new Rect(0, 0, size.width, size.height);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
int quality = 100;
image.compressToJpeg(rectangle, quality, stream);
Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
FaceDetector detector = new FaceDetector(size.width, size.height, 5);
FaceDetector.Face[] faces = new FaceDetector.Face[5];
int numFaces = detector.findFaces(bitmap, faces);
textView.setText("numFaces = " + numFaces);

Any ideas? 有任何想法吗? fixes? 修复?

I think you should check whether your bitmap data is correct firstly. 我认为你应该首先检查你的位图数据是否正确。 You must setPreviewSize before startPreview . 您必须在startPreview之前setPreviewSize check whether the size is same as your preview data. 检查大小是否与预览数据相同。 or you can hard code it to (640, 480) for a test. 或者你可以硬编码到(640,480)进行测试。 If your bitmap is correct. 如果你的位图是正确的。 maybe the API cannot work due to the input data quality. 由于输入数据质量,API可能无法工作。 you can dump some data, and try other app or lib, such as OpenCV, to verify. 您可以转储一些数据,并尝试其他应用程序或库(如OpenCV)进行验证。 Good luck. 祝好运。

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

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