OpenCV for Android不会在手机屏幕上绘制面部矩形以进行面部检测,但会在Android Studio中的模拟器屏幕上绘制矩形

时间:2016-06-08 09:28:37

标签: android opencv face-detection

OpenCV人脸检测程序不会在手机屏幕(Nexus 4)上的脸部周围绘制矩形,但它会在Android Studio中的模拟器上绘制矩形。这是代码:

@Override
public Mat onCameraFrame(Mat aInputFrame) {
    // Create a grayscale image[enter image description here][1]
    Imgproc.cvtColor(aInputFrame, grayscaleImage, Imgproc.COLOR_RGBA2GRAY);

    MatOfRect faces = new MatOfRect();
    MatOfRect eye = new MatOfRect();

    // Use the classifier to detect faces
    if (faceDetect != null ) {
        faceDetect.detectMultiScale(grayscaleImage, faces, 1.1, 2, 2,
                new Size(absoluteFaceSize, absoluteFaceSize), new Size());

        Log.d(TAG,"Face Detected");

    }

    // If there are any faces found, draw a rectangle around it
    Rect[] facesArray = faces.toArray();

    for (int i = 0; i <facesArray.length; i++) {
        Rect rG = facesArray[i];
        Imgproc.rectangle(aInputFrame, rG.tl(), rG.br(), new Scalar(0, 255, 0), 3);
    }


    if(eyeDetect != null ){
        eyeDetect.detectMultiScale(grayscaleImage, eye, 1.1, 2, 2,
                new Size(absoluteEyeSize, absoluteEyeSize), new Size());

        Log.d(TAG,"Eyes Detected");
    }

    Rect[] eyeArray = eye.toArray();
    for (int i = 0; i <eyeArray.length; i++) {
        Rect rR = eyeArray[i];
        Imgproc.rectangle(aInputFrame, rR.tl(), rR.br(), new Scalar(255, 0, 0), 3);
    }

    return aInputFrame;
}

绿色和红色矩形在模拟器中绘制,但不在手机中。 请让我知道如何解决这个问题。我使用的是Android Studio 2.2和OpenCVLibray310。

0 个答案:

没有答案