1 | initial version |
#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 ;)
2 | No.2 Revision |
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 ;)