Younestheboss
Messages postés13Date d'inscriptionvendredi 30 mars 2012StatutMembreDernière intervention19 décembre 2013
-
1 déc. 2013 à 19:52
tous est OK sauf lors de la compilation je recois l'erreur suivante : Unhundled exeception in prog.exe:0x0000005:Access violation si quelqu'un peut m'aidé SVP
static const double pi = 3.14159265358979323846;
#define N 500
inline static double square(int a)
{
return a * a;
}
int thresh = 11;
double scale = 1;
// define a trackbar callback
void on_trackbar(int h)
{
int b = h-11;
if(b<0)
scale = -1.0/(b-1);
else if(b>0)
scale = b*1.0+1;
else
scale = 1.0;
printf("scale %d\n",b);
}
// Create a string that contains the exact cascade name
const char* cascade_name =
"C:/Program Files/OpenCV2.2/data/haarcascades/haarcascade_frontalface_alt.xml";
/* "haarcascade_profileface.xml";*/
// Function prototype for detecting and drawing an object from an image
void detect_and_draw( IplImage* image , int scale,int min_neighbors,int min_size,IplImage* faceimg, CvRect* tmprect );
/*
This will pop up a small box with "Hello World" as the text.
@author: Gavin Page, gsp8334@cs.rit.edu
@date: 28 November 2005
*/
int main( int argc, char** argv ) {
CvCapture* cap = cvCaptureFromAVI("../images/sample.avi");
return 0;
}
// Function to detect and draw any faces that is present in an image
void detect_and_draw( IplImage* img, int scale,int min_neighbors,int min_size,IplImage* faceimg, CvRect* tmprect )
{
// Create memory for calculations
static CvMemStorage* storage = 0;
// Create a new Haar classifier
static CvHaarClassifierCascade* cascade = 0;
//int scale = 1;
// Create a new image based on the input image
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
// Create two points to represent the face locations
CvPoint pt1, pt2;
int i;
// Check whether the cascade has loaded successfully. Else report and error and quit
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return;
}
// Allocate the memory storage
storage = cvCreateMemStorage(0);
// Create a new named window with title: result
cvNamedWindow( "result", 1 );
// 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( img, cascade, storage,
1.1, min_neighbors, CV_HAAR_DO_CANNY_PRUNING,
cvSize(min_size, min_size) );
// Loop the number of faces found.
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
// Create a new rectangle for drawing the face
// CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
tmprect = (CvRect*)cvGetSeqElem( faces, i );
if (tmprect->height<= 0 ) continue;
cvSetImageROI( img, cvRect(tmprect->x*scale,tmprect->y*scale,tmprect->width*scale,tmprect->height*scale) );
//sprintf(file_num,"G:\\faces_from_movie\\%d.jpg",int(framenum));
//cvReleaseImage(faceimg);
faceimg = cvCreateImage(cvSize(tmprect->width*scale,tmprect->height*scale),img->depth,img->nChannels);
//faceimg = cvCloneImage(img);
cvCopyImage(img,faceimg);
cvNamedWindow("The Face", 0);
cvShowImage("The Face", faceimg);
cvResetImageROI(img);
// Find the dimensions of the face,and scale it if necessary
pt1.x = tmprect->x*scale;
pt2.x = (tmprect->x+tmprect->width)*scale;
pt1.y = tmprect->y*scale;
pt2.y = (tmprect->y+tmprect->height)*scale;
// Draw the rectangle in the input image
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
}
}
// Show the image in the window named "result"
cvShowImage( "result", img );
//IplROI roi = cvRectToROI(&r
// Release the temp image created.
cvReleaseImage( &temp );
}