开发者

slow face detection android

开发者 https://www.devze.com 2023-03-27 18:25 出处:网络
Hi my face detection thread is working too slow, I call this thread from onPreviewFrame only if the thread is not working else i just skip the call and after the thread detect face i call onDraw insid

Hi my face detection thread is working too slow, I call this thread from onPreviewFrame only if the thread is not working else i just skip the call and after the thread detect face i call onDraw inside the view to draw rectangle

    public void run() {
        FaceDetector faceDetector = new FaceDetector(bitmapImg.getWidth(), bitmapImg.getHeight(), 1);
        numOfFacesDetected = faceDetector.findFaces(bitmapImg, detectedFaces);

        if (numOfFacesDetected != 0) {
            detectedFaces.getMidPoint(eyesMidPoint);
            eyesDistance = detectedFaces.eyesDistance();

            handler.post(new Runnable() {
                public void run() {
                    mPrev.invalidate();
                    // turn off thread lock
                }
            });

            mPrev.setEyesDistance(eyesDistance);
            mPrev.setEyesMidPoint(eyesMidPoint);
        }

        isThreadWorking = false;
    }


public void onPreviewFrame(byte[] yuv, Camera camera) {

if (isThreadWorking) return;

    isThreadWorking = true;
    ByteBuffer bbuffer = ByteBuffer.wrap(yuv);
    bbuffer.get(grayBuff_, 0, bufflen_);

    detectThread = new FaceDetectT开发者_运维技巧hread(handler);
    detectThread.setBuffer(grayBuff_);
    detectThread.start();

my questions is maybe because am working with bitmap and not gray scale it's taking too long ? how can i improve the speed ?


The FaceDetector API is not really made to process frames in a live preview. It's way to slow for that.

If you are running on a fairly new device, a better option is to use the FaceDetectionListener API in Android 14+. It is very fast and can be used to create an overlay on a preview SurfaceHolder.

0

精彩评论

暂无评论...
验证码 换一张
取 消