Ask Your Question

Revision history [back]

I'm developing a project about face recognition on android. I meet a problem after detect face region

I meet a problem in the onCameraFrame() function. After detect face in the function, I want to get the face region, and then create a new Mat to save the face area. but there are a problem.My code is:

mRgba = inputFrame.rgba();
    Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGB2GRAY);
    int height = mGray.rows();
    if (Math.round(height * mRelativeFaceSize) > 0) {
        mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
    }
    MatOfRect faces = new MatOfRect();
    if (mJavaDetector != null)
        mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++)
        Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
    Mat faceImg = new Mat(mGray,facesArray[0]);

    return mRgba;

I want to get the face area, so I use the gray image to init the new Mat data. My error isimage description

while the program is right if I move the penultimate sentence

Mat faceImg = new Mat(mGray,facesArray[0]);

I want to know why is it. thanks

click to hide/show revision 2
retagged

updated 2014-04-26 00:34:19 -0600

berak gravatar image

I'm developing a project about face recognition on android. I meet a problem after detect face region

I meet a problem in the onCameraFrame() function. After detect face in the function, I want to get the face region, and then create a new Mat to save the face area. but there are a problem.My code is:

mRgba = inputFrame.rgba();
    Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGB2GRAY);
    int height = mGray.rows();
    if (Math.round(height * mRelativeFaceSize) > 0) {
        mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
    }
    MatOfRect faces = new MatOfRect();
    if (mJavaDetector != null)
        mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++)
        Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
    Mat faceImg = new Mat(mGray,facesArray[0]);

    return mRgba;

I want to get the face area, so I use the gray image to init the new Mat data. My error isimage description

while the program is right if I move the penultimate sentence

Mat faceImg = new Mat(mGray,facesArray[0]);

I want to know why is it. thanks