相机人脸检测侦听器在相机变焦时无法正常工作

时间:2018-05-16 06:40:29

标签: android camera android-camera face-detection camera-api

启动预览后,我已将FaceDetection侦听器添加到我的相机中。因此,当面部正在检测时,我正在回调,并且在此基础上,我计算面部区域与预览屏幕的比率。如果百分比较低,则取一些值我会缩放相机。

但问题是,在缩放后面部检测不起作用,没有在FaceDetectionListener上获得回调。

import binascii, re
infile = my_file.bin
with open(infile, "rb") as f:
    data = binascii.b2a_hex(f.read()).upper()

for matches in list(data):
    match_list = []
    matches = re.findall(b'\x24' + b'\x([A-Z]).{3,10}', data)
    match_list.append(matches)

}

缩放代码 -

public class FaceDetectionListener implements Camera.FaceDetectionListener {

@Override
public void onFaceDetection( final Camera.Face[] faces, Camera camera ) {
    Log.i(TAG, "onFaceDetection " + faces.length);
    if ( faces.length > 0 ) {

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                Rect uRect = null;
                //Do something after 100ms
                for ( int i = 0; i < faces.length; i++ ) {
                    int left = faces[i].rect.left;
                    int right = faces[i].rect.right;
                    int top = faces[i].rect.top;
                    int bottom = faces[i].rect.bottom;
                    uRect = new Rect(left, top, right, bottom);

                    Log.d("FaceDetection", "face detected: " + faces.length +
                            " Face 1 Location Left: " + left +
                            " Right: " + right + " Top: " + top + " Bottom: " + bottom + " Area: " + (uRect.height() * uRect.width()));

                }

                FaceDetect faceDetect = new FaceDetect();
                faceDetect.setArea(uRect.height() * uRect.width());

                EventBus.getDefault().post(faceDetect);
            }
        }, 500);

    }
}

0 个答案:

没有答案