简体   繁体   English

FaceDetector检测方法中的图像尺寸不一致

[英]Inconsistent Image dimensions in FaceDetector detect method

I am trying to detect and crop the image of a face using the com.google.android.gms.vision.face.FaceDetector class, 我正在尝试使用com.google.android.gms.vision.face.FaceDetector类检测并裁剪脸部图像,

The facedetector object is created as, 人脸检测器对象创建为

 detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.FAST_MODE)
            .setProminentFaceOnly(true)
            .setTrackingEnabled(true)
            .build();


 detector.setProcessor(
            new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
                    .build());

The camera source is created with Camera2 Api as, 相机源是使用Camera2 Api创建的,

mCameraSource = new CameraSource.Builder(context, detector)
                .setFacing(CameraSource.CAMERA_FACING_FRONT)
                .setRequestedFps(15.0f)
                .build();

Then on a button click the takePicture method in CameraSource is called to process the Image as, 然后在按钮上单击CameraSource中的takePicture方法,以将Image处理为

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());

            }
        });

But I am getting the following error, 但是我收到以下错误,

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)

Finally I got it to work, to detect faces from files, 最终,我开始使用它,可以从文件中检测人脸,

The solution is to create the detector object with setting, trackingEnabled ->false, and if you want to track multiple faces, setProminentFaceOnly->false. 解决方案是使用设置trackingEnabled-> false创建检测器对象,如果要跟踪多个面部,请设置setProminentFaceOnly-> false。

With tracking enabled, the detector works well with an associated camera preview to track the face with id. 启用跟踪后,检测器可以很好地与关联的摄像机预览一起使用,以跟踪具有id的面部。 Will post a detailed explanation of the reason behind this solution, as of create the detector object as, 从创建检测器对象开始,将详细说明此解决方案背后的原因,

detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.FAST_MODE)
            .setProminentFaceOnly(false) // <-- set to false
            .setTrackingEnabled(false) // <-- set to false
            .build();

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

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