我正在尝试使用。检测并裁剪脸部图像 com.google.android.gms.vision.face.FaceDetector类,
facedetector对象创建为,
detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.FAST_MODE)
.setProminentFaceOnly(true)
.setTrackingEnabled(true)
.build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
.build());
摄像机信号源使用Camera2 Api as
创建mCameraSource = new CameraSource.Builder(context, detector)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(15.0f)
.build();
然后在按钮上单击调用CameraSource中的takePicture方法以处理Image as,
mCameraSource.takePicture(null, new CameraSource.PictureCallback(){
@Override
public void onPictureTaken(byte[] bytes) {
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap temp = BitmapFactory.decodeByteArray(bytes, 0,
bytes.length, options);
Frame frame = new Frame.Builder().setBitmap(temp).build();
SparseArray<Face> faces =detector.detect(frame);
System.out.println("faces: "+faces.size());
}
});
但是我收到以下错误,
inconsistent image dimensions
Native face detection failed
java.lang.RuntimeException: Error detecting faces.
com.google.android.gms.vision.face.NativeFaceDetectorImpl.detectFacesJni(Native Method)
at com.google.android.gms.vision.face.FaceDetector.detect(Unknown Source:41)
答案 0 :(得分:0)
最后我让它工作,从文件中检测面孔,
解决方案是使用设置创建检测器对象, trackingEnabled - &gt; false,如果你想跟踪多个面,setProminentFaceOnly-&gt; false。
启用跟踪后,探测器可以与相关的摄像头预览配合使用,以跟踪带有ID的人脸。将发布此解决方案背后原因的详细解释,如创建探测器对象,
detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.FAST_MODE)
.setProminentFaceOnly(false) // <-- set to false
.setTrackingEnabled(false) // <-- set to false
.build();