Home > Software engineering >  Based on opencv face detection, face how to reduce the error in the detection of video, leak problem
Based on opencv face detection, face how to reduce the error in the detection of video, leak problem

Time:09-23



above problems o great god help me to change a
The code below

# include "CV. H"
# include "highgui. H"

H # include "Windows."

#include
#include
#include
#include
#include
#include
#include
#include
#include


# ifdef _EiC
# define WIN32
# endif

The static CvMemStorage * storage=0;
The static CvHaarClassifierCascade * cascade=0;

Void detect_and_draw (IplImage * image);

Const char * cascade_name=
"Haarcascade_frontalface_alt. XML";
/* "haarcascade_profileface. XML"; */

Int main (int arg c, char * * argv)
{
//HWND MyWin;
Cascade_name="haarcascade_frontalface_alt2. XML";
Cascade=(CvHaarClassifierCascade *) cvLoad (cascade_name, 0, 0, 0).

//CvCapture * pCap=cvCreateCameraCapture (1);//- 1 can be here, but my computer is showing YouCam software,
////OpenCV will invoke the camera by default, and not call system drive
//IplImage * frame=NULL;

//if (cvCreateCameraCapture==NULL)
//{
//return (0);
//}

//cvNamedWindow (" Camera, "CV_WINDOW_FULLSCREEN);

//while ((frame=cvQueryFrame (pCap))!=0 & amp; & CvWaitKey (20).=27)
//{
//frame=cvQueryFrame (pCap);
//cvShowImage (" Camera, "frame).
//}

//cvReleaseCapture (& amp; PCap);
//cvDestroyWindow (" Camera ");


if( ! Cascade)
{
Fprintf (stderr, "ERROR: Could not load classifier cascade \ n");
return -1;
}
Storage=cvCreateMemStorage (0);
//cvNamedWindow (" result ", 1);

//const char * filename="op. JPG";
//IplImage * image=cvLoadImage (filename, 1);

//if (image)
//{
//detect_and_draw (image);
//cvWaitKey (0);
//cvReleaseImage (& amp; Image);
//}

//cvDestroyWindow (" result ");

//========================================================
//CvCapture is a structure that is used to store image capture the required information,
//opencv provides two ways from the external image capture, one from the camera,
//is obtained by decoding video images, two ways must be from the first frame of a frame is a frame
//in order to obtain, so always keep after each frame to obtain the corresponding condition and parameter,
//get from video file, for example, need to keep the video file name, the corresponding * * * * * *
//type, next time if you want to get which will need to decode a frame and so on, this information is stored in the
//CvCapture structure, each get a frame, after all these information will be updated, for the next frame
//need to new information to obtain API interface
//=======================================================
CvCapture * capture=0;
//===========================================================
//IplImage is a structure type, used to hold a frame of image information, which is a frame
//image of all pixels of a matrix
//===========================================================
Frame IplImage * and * frame_copy=0;

//create a window, with the "result" as a window identifier
CvNamedWindow (" source ", 1);

//==========================================
//initialize a video capture operation,
//tell the capture of the underlying API. I'd like to Capture1 avi capture images,
//the underlying API will detect and select the corresponding * * * * * * and prepare
//==============================================
The capture=cvCaptureFromFile (" papi. Avi ");

//if the initialization failed, then the capture as null pointer, the program stops,
//otherwise enter capture cyclic
If (capture)
{
//capture cycle
For (;; )
{
//call cvGrabFrame, let the underlying API decode a frame image
//if decoding failure, will exit the loop
//if successful, the decoded images stored in the underlying API cache
if( ! CvGrabFrame (capture))
break;

//will get the image decoding information from the cache converted into IplImage format in the frame for
Frame=cvRetrieveFrame (capture);

//if failed to get the cache or conversion, the exit loop
if( ! Frame)
break;
Detect_and_draw (frame);

//the frame of the image information shown in the result window
//detect_and_draw (frame);
CvShowImage (" source ", the frame);

//pause for a moment, let you look at the picture
//Sleep (10);

//if you knock on the keyboard, then exit the program, or continue to capture the next frame
If (cvWaitKey (10) & gt;=0)
break;
}

//to clear up the stack memory before exit the program, so that memory leaks
//cvReleaseImage (& amp; Frame); Note don't need it, because the frame is to capture the video, not allocate memory alone, without release, when released the capture frame naturally released,

//exit before the end of the underlying API capture operation, lest they manger
//such as will make the other programs can access has been opened their files
CvReleaseCapture (& amp; The capture);

}
CvDestroyWindow (" source ");
//cvDestroyWindow (" result ");
return 0;
}


Void detect_and_draw (IplImage * img)
{
Double scale=1.2;
The static CvScalar colors []={
,0,255 {{0}}, {{0128255}}, {{0255255}}, {{0255, 0}},
{{255128, 0}}, {{255255, 0}}, {{0, 255}}, {{255,0,255}}
};//Just some pretty colors to the draw with

//Image Preparation
//
IplImage * gray=cvCreateImage (cvSize (img - & gt; Width, img - & gt; Height), 8, 1);
IplImage * small_img=cvCreateImage (cvSize (cvRound (img - & gt; Width/scale), cvRound (img - & gt; Height/scale)), 8, 1);
CvCvtColor (img, gray, CV_BGR2GRAY);
CvResize (gray, small_img CV_INTER_LINEAR);

CvEqualizeHist (small_img small_img);//histogram equalization

//Detect objects if any
//
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related