cascade classifier doesnot work for image input

asked 2016-02-16 02:23:49 -0500

GANESH PRASAATH L gravatar image

updated 2016-02-16 02:37:40 -0500

given below is my code

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main()
{
    Mat new=imread("F:\new.jpg");
    namedWindow("HAAR");
    CascadeClassifier face_cascade; 
    vector<Rect> faces;
    Mat frame_gray;

    cvtColor( new, frame_gray, CV_BGR2GRAY );
    equalizeHist( frame_gray, frame_gray );
    if( !face_cascade.load( "haarcascade_frontalface_alt.xml") )
    { 
      printf("--(!)Error loading\n");
      return -1;
    };
    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++ )
    {
         Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
         ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
    }
    imshow("HAAR", frame );
}

MS visual studio 2010 and opencv 2.4.9 are used. no error is displayed build is successful

edit retag flag offensive close merge delete

Comments

2

Please format your code (as it's done now) and show us the image you are using. By the way, it is a bad habit to name your image "new" and you haven't checked that your image is loaded. Try to use "F:\\new.jpg" (with two \ instead of one).

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2016-02-16 02:40:54 -0500 )edit

now replaced variable name 'new' with 'frame' sorry to post the wrong code

GANESH PRASAATH L gravatar imageGANESH PRASAATH L ( 2016-02-17 02:24:20 -0500 )edit