Smile detection using opencv on android

Asked

Viewed 246 times

0

Hello, I’m having difficulties to detect smiles using opencv on android. I can make the detection of faces and eyes very well using Aar Cascade but only the detection of smiles is not working using this method.

private Mat image, originalImage, imgGray;
private CascadeClassifier face;
private CascadeClassifier eye; //atributos
private CascadeClassifier smile;
private Size dsize = new Size(480, 640);
private MatOfRect faceDetections;
private MatOfRect eyeDetections;
private MatOfRect smileDetections;
private boolean center;

public FaceDetection(Mat imagem, Mat imgCinza) {
    //load the haarcascade's archives to detect faces, eyes and smiles.

    this.face = new CascadeClassifier("/storage/emulated/0/data/haarcascade_frontalface_alt.xml");
    this.face.load("/storage/emulated/0/data/haarcascade_frontalface_alt.xml");
    this.eye = new CascadeClassifier("/storage/emulated/0/data/haarcascade_eye_tree_eyeglasses.xml");
    this.eye.load("/storage/emulated/0/data/haarcascade_eye_tree_eyeglasses.xml");
    this.smile = new CascadeClassifier("/storage/emulated/0/data/haarcascade_myhaar.xml");
    this.smile.load("/storage/emulated/0/data/haarcascade_myhaar.xml");
    this.originalImage = imagem;
    this.imgGray = new Mat();
    this.image = new Mat();
    Imgproc.resize(imgCinza, this.imgGray, dsize);
    Imgproc.resize(this.originalImage, this.image, dsize);
    this.faceDetections = new MatOfRect();
    this.eyeDetections = new MatOfRect();
    this.smileDetections = new MatOfRect();
}

public void detectate() {
    eye.detectMultiScale(imgGray, eyeDetections);
    smile.detectMultiScale(imgGray, smileDetections);
    face.detectMultiScale(imgGray, faceDetections);
    faceDetect();
    System.out.println("Funcionou");
}

As shown in the code, I am loading the Cascades passing the path of the haarcascades xml files. My doubt is because only the detection of faces and eyes works, being that I am using a haarcascade of the own opencv for the detection of smiles and only this one does not work. I hope I’ve made my difficulty clearer.

  • What difficulties? You do not indicate what they are, and so it is difficult for someone to help you. See that this site is not a forum, and yes a question and answer site. Do the [tour], read [Ask], then come back here and edit your question to improve it. Explain what’s wrong and provide examples of your code.

  • So far as I know they’re just for face detection, not exactly identifying smiles, maybe they need other features

  • I saw that you added the code. Very well. But it is still not clear the following: you use several Scades, one to detect front faces (haarcascade_frontalface_alt), one to detect eyes with or without glasses (haarcascade_eye_tree_eyeglasses), and one that looks customized, that is, made by you and not standard Opencv (haarcascade_myhaar). Is this the one that should detect smiles? If yes and it is not working, the problem is in your training. Did you use images only with smiles (positive) and anything else, that is, no smiles (negative)? Add details that I vote to open.

  • @Andrécarvalho Actually this algorithm is good at detecting anything that can be exemplified in images. Even bananas. :) The problem is that it is not very robust to variations that escape from the images used in training.

  • The moment the algorithm can identify Monalisa’s smile (used as a control, without being in training), I will say that it is good

  • So, this haarcascade was done by me after testing the ones that already come in opencv itself that didn’t work. And yes, in the training I used as positive images only images with smiles and as negative images images of any other things. I used this video as the basis to create my haarcascade. https://www.youtube.com/watch?v=Dg-4MoABv4I

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.