Ask Your Question
1

simple face recognition

asked 2013-09-03 05:00:09 -0500

iacoposk8 gravatar image

updated 2013-09-03 05:04:33 -0500

berak gravatar image

Hello to all! I'm looking for an example (as simple as possible) to do the face detection. I found this tutorial: http://dasl.mem.drexel.edu/~noahKuntz/openCVTut11.html but I get this error:

error: could not convert '{{0, 0, 255}}' from '<brace-enclosed initializer list>' to 'CvScalar'

how to solve? or otherwise: you know a better tutorial? thanks :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-09-03 05:27:25 -0500

berak gravatar image

updated 2013-09-03 05:29:28 -0500

i think, you should use the c++ api, not the old c one.


#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"    
#include <stdio.h>   

using namespace cv;

int main( int argc, const char** argv )
{
    CascadeClassifier face_cascade("/path/to/haarcascade_frontalface_alt.xml"); // PUT YOUR OWN HERE!
    if ( face_cascade.empty() ) { printf("Error loading cascade file\n"); return -1; };

    Mat frame = imread("/path/to/image/with/faces.jpg"); // PUT YOUR OWN HERE!
    if ( frame.empty() ) { printf("Error loading image file\n"); return -1; };

    Mat frame_gray;
    cvtColor(frame,frame_gray,CV_BGR2GRAY);

    std::vector<Rect> faces;
    face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

    for ( size_t i=0; i<faces.size(); i++ ) 
    {
        rectangle( frame, faces[i], Scalar( 255, 0, 255 ), 2 );
    }
    imshow("faces",frame);
    waitKey();
    return 0;
}

don't think i can do with less ;)

edit flag offensive delete link more

Comments

1

I read this in the console, how can I solve? error: 'CV_BGR2GRAY' was not declared in this scope error: 'CV_HAAR_SCALE_IMAGE' was not declared in this scope

iacoposk8 gravatar imageiacoposk8 ( 2013-09-03 07:13:52 -0500 )edit
1

hmm, what version are you using ?

if you (accidentally?) build from github master, then it's:

COLOR_RGB2GRAY and HAAR_SCALE_IMAGE

berak gravatar imageberak ( 2013-09-03 07:24:21 -0500 )edit

yes, I downloaded everything from git. COLOR_RGB2GRAY works! but on HAAR_SCALE_IMAGE I still have the same problem

iacoposk8 gravatar imageiacoposk8 ( 2013-09-04 03:53:16 -0500 )edit

whaa, sorry , my bad.

CASCADE_SCALE_IMAGE

(for 2.9)

berak gravatar imageberak ( 2013-09-04 04:11:14 -0500 )edit

Now the project is fully completed. I open a terminal window that says: Error loading cascade file:

Process returned 255 (0xFF) execution time: 1.174 s

iacoposk8 gravatar imageiacoposk8 ( 2013-09-04 04:36:44 -0500 )edit

believe the error. it could not find it. there's something wrong with your path. what did you use there ?

berak gravatar imageberak ( 2013-09-04 04:51:38 -0500 )edit

I did not understand your question (my english is bad :))

iacoposk8 gravatar imageiacoposk8 ( 2013-09-04 05:06:39 -0500 )edit

no prob.

CascadeClassifier face_cascade("/path/to/haarcascade_frontalface_alt.xml");

what did you change it to ? you have to change it to the actual location of the xml file.

(same thing for your image, btw)

berak gravatar imageberak ( 2013-09-04 05:09:04 -0500 )edit

of course! are a fool! now everything works perfectly. thank you! you have been infinitely gentle :)

iacoposk8 gravatar imageiacoposk8 ( 2013-09-04 06:46:22 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-09-03 05:00:09 -0500

Seen: 2,525 times

Last updated: Sep 03 '13