Smile detection error using opencv-java

asked 2014-09-24 10:11:01 -0600

Hello friends,

I am working on a project where I have to detect smiles using opencv, unfortunately the project is in java for which finding some advanced stuff has proved considerably difficult. When I am using haarcascade_smile as facecascade1 in below code, I get around 30-40 smiles. I have no idea what is the problem, I saw the exact same way a guy did, and its working for him. Kindly let me know. Thank you.

Code :

public Mat detect(Mat inputframe) {
        Mat mRgba = new Mat();
        Mat mGrey = new Mat();
        MatOfRect faces = new MatOfRect();
        inputframe.copyTo(mRgba);
        inputframe.copyTo(mGrey);
        Imgproc.cvtColor(mRgba, mGrey, Imgproc.COLOR_BGR2GRAY);
        Imgproc.equalizeHist(mGrey, mGrey);
        face_cascade.detectMultiScale(mGrey, faces);
        System.out.println(String.format("Detected %s face",
                faces.toArray().length));
        MatOfRect smileDetections = new MatOfRect();
        face_cascade1.detectMultiScale(mGrey,smileDetections);
        System.out.println(String.format("Detected %s smiles",smileDetections.toArray().length));
        for (Rect rect : faces.toArray()) {
            Point center = new Point(rect.x + rect.width * 0.5, rect.y
                    + rect.height * 0.5);
            Core.ellipse(mRgba, center, new Size(rect.width * 0.5,
                    rect.height * 0.5), 0, 0, 360, new Scalar(255, 0, 255), 4,
                    8, 0);
        }
        return mRgba;
    }
edit retag flag offensive close merge delete

Comments

1

you should apply the smile detection to the ROIs from the previous face-detection, not the whole image

berak gravatar imageberak ( 2014-09-25 03:10:40 -0600 )edit