Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having some problems in finding codes for Opencv in java for face recgonizt

ID: 3872285 • Letter: I

Question

I'm having some problems in finding codes for Opencv in java for face recgoniztion, I want a code that says if the 2 pictures are matched or not

Explanation / Answer

// Detect face on the input image and returns a rectangle for the detected region using the given Haar Cascade. CvRect detectFaceInImage(IplImage *inputImg, CvHaarClassifierCascade* cascade) { // Smallest size face. CvSize minFeatureSize = cvSize(20, 20); // Only one face ata . int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH; // How detailed should the search be. float search_scale_factor = 1.1f; IplImage *detectImg; IplImage *greyImg = 0; CvMemStorage* storage; CvRect rc; double t; CvSeq* rects; CvSize size; int i, ms, nFaces; storage = cvCreateMemStorage(0); cvClearMemStorage( storage ); // use a greyscale copy of the image if image is colored. detectImg = (IplImage*)inputImg; if (inputImg->nChannels > 1) { size = cvSize(inputImg->width, inputImg->height); greyImg = cvCreateImage(size, IPL_DEPTH_8U, 1 ); cvCvtColor( inputImg, greyImg, CV_BGR2GRAY ); detectImg = greyImg; // Use the greyscale image. } // Detect all the faces in the greyscale image. t = (double)cvGetTickCount(); rects = cvHaarDetectObjects( detectImg, cascade, storage, search_scale_factor, 3, flags, minFeatureSize); t = (double)cvGetTickCount() - t; ms = cvRound( t / ((double)cvGetTickFrequency() * 1000.0) ); nFaces = rects->total; printf("Face Detection took %d ms and found %d objects ", ms, nFaces); // Get the first detected face (the biggest). if (nFaces > 0) rc = *(CvRect*)cvGetSeqElem( rects, 0 ); else rc = cvRect(-1,-1,-1,-1); // Couldn't find the face. if (greyImg) cvReleaseImage( &greyImg ); cvReleaseMemStorage( &storage ); //cvReleaseHaarClassifierCascade( &cascade ); return rc; // Return the biggest face found, or (-1,-1,-1,-1). } // Haar Cascade file, used for Face Detection. char *faceCascadeFilename = "haarcascade_frontalface_alt.xml"; // Load the HaarCascade classifier for face detection. CvHaarClassifierCascade* faceCascade; faceCascade = (CvHaarClassifierCascade*)cvLoad(faceCascadeFilename, 0, 0, 0); if( !faceCascade ) { printf("Couldnt load Face detector '%s' ", faceCascadeFilename); exit(1); } // Grab the next frame from the camera. IplImage *inputImg = cvQueryFrame(camera); // Perform face detection on the input image, using the given Haar classifier CvRect faceRect = detectFaceInImage(inputImg, faceCascade); // Make sure a valid face was detected. if (faceRect.width > 0) { printf("Detected a face at (%d,%d)! ", faceRect.x, faceRect.y); } Use 'faceRect' and 'inputImg' // Free Face Detector resources cvReleaseHaarClassifierCascade( &cascade );

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote