int main() { while(1){ IplImage *img1 = cvLoadImage("/home/ikaros/Pictures/Backtrack_Pure_by_twenty_steps_freedom.jpg"); IplImage *img2 = cvLoadImage("/home/ikaros/Pictures/Backtrack_Pure_by_twenty_steps_freedom.jpg"); cvShowManyImages("Image", 2, img1, img2); } return 0; }
// Function to detect and draw any faces that is present in an image void detect_and_draw( IplImage* temp ) { IplImage *grey = cvCreateImage(cvGetSize(temp), 8, 1); cvCvtColor(temp, grey, CV_RGB2GRAY); IplImage* face = cvCreateImage(cvSize(100,100), 8, 1); IplImage *faces_hist[NUM_FACES]; int i,j; for(i=0;i<NUM_FACES;i++) { faces_hist[i] = cvCreateImage(cvSize(100,100), 8, 1); cvZero(faces_hist[i]); } cvZero(face); // Create two points to represent the face locations CvPoint pt1, pt2, e_pt1, e_pt2; // Clear the memory storage which was used before cvClearMemStorage( storage ); // Find whether the cascade is loaded, to find the faces. If yes, then: if( cascade ) { // There can be more than one face in an image. So create a growable sequence of faces. // Detect the objects and store them in the sequence CvSeq* faces = cvHaarDetectObjects( grey, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(40, 40) ); // Loop the number of faces found. if (faces) printf("Number of faces: %d\n", faces->total); for( i = 0; i < (faces ? faces->total : 0); i++ ) { // Create a new rectangle for drawing the face CvRect* r = (CvRect*)cvGetSeqElem( faces, i ); // Find the dimensions of the face,and scale it if necessary pt1.x = r->x; pt2.x = (r->x+r->width); pt1.y = r->y; pt2.y = (r->y+r->height); cvSetImageROI(grey, cvRect(pt1.x, pt1.y, r->width, r->height)); CvSeq* eyes = cvHaarDetectObjects(grey, cascade_eyes, storage, 1.1, 5, 0, cvSize(25,15)); printf("Eyes: %p num: %d\n", eyes, eyes->total); for( j=0;j < (eyes ? eyes->total : 0); j++ ) { CvRect *e = (CvRect*)cvGetSeqElem(eyes, j); e_pt1.x = e->x; e_pt2.x = (e->x+e->width); e_pt1.y = e->y; e_pt2.y = (e->y+e->height); cvRectangle(grey, e_pt1, e_pt2, CV_RGB(255,255,255), 3, 8, 0); } cvResize(grey, face, CV_INTER_LINEAR); cvResetImageROI(grey); if (i < NUM_FACES) cvEqualizeHist(face, faces_hist[i]); // Draw the rectangle in the input image cvRectangle( grey, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 ); } } // Show the image in the window named "result" //cvShowImage( "result", temp ); cvShowManyImages("result", 6, temp, grey, face, faces_hist[0], faces_hist[1], faces_hist[2]); // Release the temp image created. cvReleaseImage( &face ); cvReleaseImage( &grey ); for(i=0;i<NUM_FACES;i++) cvReleaseImage(&faces_hist[i]); }