0

I am trying to implement Face detection viola jones classifier using opencv cascade. This is the code i am using:

int main( ){
SYSTEMTIME tm;

GetLocalTime(&tm);
printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
//CString t = CTime::GetCurrentTime().Format("%H:%M:%S:%MS");
Mat image;
Mat frame_gray;

image = imread("test.jpg", CV_LOAD_IMAGE_COLOR); 
namedWindow( "window1", 1 );   imshow( "window1", image );


// Load Face cascade (.xml file)
CascadeClassifier face_cascade;
face_cascade.load( "cascades.xml" );



cvtColor( image, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );


GetLocalTime(&tm);
printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
float pyramidScale = 1.5f;
// Detect faces
std::vector<Rect> faces;
face_cascade.detectMultiScale( frame_gray, faces, pyramidScale, 3, 0, Size(20, 20), Size(50, 50));

GetLocalTime(&tm);
printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);

// Draw circles on the detected faces
for( int 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( image, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 255, 255 ), 4, 8, 0 );
}

imshow( "Detected Face", image );


SYSTEMTIME tm1;
GetLocalTime(&tm);
printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
//cout<< "Time : "<<tm.wHour<<":"<<tm.wMinute << ":"<< tm.wSecond << ":" << tm.wMilliseconds << "\n";
waitKey(0);                  
return 0;
}

The problem is it says this is viola jones implementation in opencv and usually takes 30fps to run (from the author side) but its taking 6 seconds to run a normal HD image for face detection of around 1920x1080. I wanted to ask is the implementation right or is there any problem with the way i am implementing the method and is there any way i can make it faster ? The cascade.xml is a file i trained using sample images. Thank you.

Hadi
  • 307
  • 6
  • 20
  • you're looking for faces between 20 and 50 pixels size in an hd-image ? well, yes, that will take long... the snaller your image, the faster it will get. also, try one of the lbpcascades, they're a bit less precise, but *much* faster! – berak Oct 13 '14 at 10:15
  • yes the HD image is the sample image set i am using its a tilted shot of a street from a high point. I will give lbpcascades a shot thanks – Hadi Oct 14 '14 at 06:17
  • hmm, if your camera is shooting down from some lamppost, you will no more get a real 'front-face' view of the persons. – berak Oct 14 '14 at 06:29
  • Hi basically the camera gets front and side view of the persons but as they are walking across the street and the camera is perpendicular to the street so get side and back face view too. – Hadi Oct 15 '14 at 01:27

0 Answers0