Example #1
1
 /** @function main */
 int main( int argc, const char** argv )
 {
   CvCapture* capture;
   Mat frame;

   //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

   //-- 2. Read the video stream
   capture = cvCaptureFromCAM( -1 );
   // if( capture )
   // {
   //   while( true )
   //   {
   // frame = cvQueryFrame( capture );

   // //-- 3. Apply the classifier to the frame
   //     if( !frame.empty() )
   //     { detectAndDisplay( frame ); }
   //     else
   //     { printf(" --(!) No captured frame -- Break!"); break; }

   //     int c = waitKey(10);
   //     if( (char)c == 'c' ) { break; }
   //    }
   // }
    frame = cvLoadImageM( "Salman-Khan.jpg");
    detectAndDisplay( frame ); 

   return 0;
 }
/**
 * @function main
 */
int main( void )
{
  VideoCapture capture;    //摄像头
  Mat frame;               //frame用于保存摄像头获取的每帧画面

  //-- 1. 用xml文件初始化级联分类器
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

  //-- 2. 打开摄像头
  capture.open( -1 );
  if( capture.isOpened() )
  {
    for(;;)   //每隔10ms检测一帧画面,除非用户按下键"C"
    {
      capture >> frame;   //capture >> frame将帧画面赋给frame

      //-- 3. 对该帧画面进行faces、eyes检测
      if( !frame.empty() )
       { detectAndDisplay( frame ); }
      else
       { printf(" --(!) No captured frame -- Break!"); break; }

      int c = waitKey(20);
      if( (char)c == 'c' ) { break; }

    }
  }
  return 0;
}
Example #3
0
 /** @function main */
 int main( int argc, const char** argv )
 {
   
   CvCapture* capture;
   Mat frame;

   //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !open_cascade.load( open_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !sad_cascade.load( sad_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !happy_cascade.load( happy_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

   //-- 2. Read the video stream
   capture = cvCaptureFromCAM( -1 );
   if( capture )
   {
     while( true )
     {
   frame = cvQueryFrame( capture );

   //-- 3. Apply the classifier to the frame
       if( !frame.empty() )
       { detectAndDisplay( frame ); }
       else
       { printf(" --(!) No captured frame -- Break!"); break; }

       int c = waitKey(10);
       if( (char)c == 'c' ) { break; }
      }
   }
   return 0;
 }
Example #4
0
int main(int argc, const char** argv){
	VideoCapture cam;
	Mat frame;

	if(! face_cascade.load(face_cascade_name)) {cerr<<"ERROR loading face cascade."<<endl; return -1;} 
	if(! eyes_cascade.load(eyes_cascade_name)) {cerr<<"ERROR loading eye cascade."<<endl; return -1;}
	
	cam.open(0);
	if(cam.isOpened()){

		while(true){
			cam.read(frame);
			if(!frame.empty()){
				detectAndDisplay(frame);
			}
			else{
				cerr<<"No captured frame."<<endl;
				break;
			}

			int c = waitKey(10);
			if((char) c == 'c')
				break;
		}

	}
	return 0;
}
Example #5
0
int main(int argc,char** argv)
{
  	//-- 1. Load the cascades
  	if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  	if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
	if( !mouth_cascade.load( mouth_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  	if( !nose_cascade.load( nose_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
	//if( !leftear_cascade.load( leftear_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  	//if( !rightear_cascade.load( rightear_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
 	//-- 2. Read the mm image
	if(argc!=2)
	{
		cout<<"usage: DisplayImage.out <Image_Path>\n"<<endl;
		return -1;	
	}
	Mat image;
	image=imread(argv[1],1);	
	//-- 3. Apply the classifier to the frame
      	if( !image.empty() )
       	{ detectAndDisplay( image ); }
      	else
       	{
		cout<<"No image data"<<endl;	
		return -1;
	}

      	int c = waitKey(0);
      	if( (char)c == 'c' ) { destroyWindow("window_name"); }

	return 0;
}
//================Function Main==================
int main( int argc, const char** argv )
{
	//-- 1. Load the cascades
 	if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
 	if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

	while (true) {

		//-- 2. Get Infrared image
		char *irBufferTemp = 0;
		IplImage* image = 0; 
		if (!image) image = cvCreateImageHeader(cvSize(640,488), 8 , 1); 
		unsigned int timestamp;

		if( freenect_sync_get_video((void**)&irBufferTemp,&timestamp,0,FREENECT_VIDEO_IR_8BIT)) 
			return NULL;
		else
		{	
			cvSetData(image, irBufferTemp, 640*1 ) ; 
			Mat IRimg(image);

			//-- 3. Detect face and display
			detectAndDisplay( IRimg );
			int c = waitKey(10);
    		if( (char)c == 'c' ) { break; }
		}
	}
	return 0;
	
}
Example #7
0
int main(int argc, char** argv)
{
	if (argc != 2)
	{
		cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
		return -1;
	}

	Mat image;
	image = imread(argv[1], IMREAD_COLOR); // Read the file

	if (!image.data) // Check for invalid input
	{
		cout << "Could not open or find the image" << std::endl;
		return -1;
	}

	//-- 1. Load the cascades
	if (!face_cascade.load(face_cascade_name)){ printf("--(!)Error loading face cascade\n"); return -1; };
	if (!eyes_cascade.load(eyes_cascade_name)){ printf("--(!)Error loading eyes cascade\n"); return -1; };

	//-- 2. Check this image
	detectAndDisplay(image);

	waitKey(0);

	return 0;
}
Example #8
0
/**
 * @function main
 */
int main( void )
{
  VideoCapture capture;
  Mat frame;

  //-- 1. Load the cascade
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

  //-- 2. Read the video stream
  capture.open( -1 );
  if( capture.isOpened() )
  {
    for(;;)
    {
      capture >> frame;

      //-- 3. Apply the classifier to the frame
      if( !frame.empty() )
       { detectAndDisplay( frame ); }
      else
       { printf(" --(!) No captured frame -- Break!"); break; }

      int c = waitKey(10);
      if( (char)c == 'c' ) { break; }

    }
  }
  return 0;
}
int main() {

  VideoCapture cap(0); // capture from default camera
  Mat frame;
  Point priorCenter(0, 0);

  face_cascade.load("haarcascade_frontalface_alt.xml"); // load face classifiers
  eyes_cascade.load("haarcascade_eye_tree_eyeglasses.xml"); // load eye classifiers

  namedWindow(face_window,
	      CV_WINDOW_AUTOSIZE |
	      CV_WINDOW_FREERATIO |
	      CV_GUI_EXPANDED);
  
  // Loop to capture frames
  while(cap.read(frame)) {
    
    // Apply the classifier to the frame, i.e. find face
    priorCenter = detectFace(frame, priorCenter);
    
    if(waitKey(30) >= 0) // spacebar
      break;
  }
  return 0;
}
Example #10
0
int main( int argc, const char** argv )
{
  CvCapture* capture;
  Mat frame;
    int fd = 0;
    int baudrate = B57600;

//    ard = new myserialtest();
//    fd = ard->serialport_init("/dev/tty.usbmodem1421", baudrate);

  //-- 1. Load the cascades
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
 
  //-- 2. Read the video stream
  capture = cvCaptureFromCAM( -1 );
  if( capture )
  {
    while( true )
    {
      frame = cvQueryFrame( capture );
      //-- 3. Apply the classifier to the frame
      if( !frame.empty() )
       { detectAndDisplay( frame, fd ); }
      else
       { printf(" --(!) No captured frame -- Break!"); break; }
      
      int c = waitKey(10);
      if( (char)c == 'c' ) { break; } 
    }
  }
    
  return 0;
}
int main( int argc, const char** argv )
{
	Mat frame;

	//-- 1. Load the cascades
	if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
	if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

	//-- 2. Read the video stream
// 	CvCapture* capture = cvCaptureFromCAM( -1 );	// 摄像头读取文件开关
	VideoCapture capture("VideoTest.avi");

	if( capture.isOpened()/*capture*/ )	// 摄像头读取文件开关
	{
		while( true )
		{
// 			frame = cvQueryFrame( capture );	// 摄像头读取文件开关
			capture >> frame;

			//-- 3. Apply the classifier to the frame
			if( !frame.empty() )
			{ detectAndDisplay( frame ); }
			else
			{ printf(" --(!) No captured frame -- Break!"); break; }

			int c = waitKey(10);
			if( (char)c == 'c' ) { break; } 

		}
	}
	return 0;
}
//Function which returns a matrix containing the imagages contained in a SINGLE folder
vector<Mat> openTrainingSet(string name)
{
	face_cascade.load(face_cascade_name);
	eyes_cascade.load(eyes_cascade_name);

	Mat image;
	Mat faceFrame;

	int imageNumberInt = 1;
	char imageNumberString[4];
	sprintf(imageNumberString, "%d", imageNumberInt);
	
	vector<Mat> out;
	image = imread("Training set/" + name + "/" + imageNumberString + ".jpg");	
	//resize(image, image, size.size(), 0, 0, INTER_NEAREST);
	//cvtColor(image, image, CV_BGR2GRAY);

	while (image.data)
	{
		image = showNormalizeFace(detectionAndDisplay(image, face_cascade, eyes_cascade), image);
		resize(image, image, size.size(), 0, 0, INTER_NEAREST);
	//	cvtColor(image, image, CV_BGR2GRAY);
		out.push_back(image);
		//imshow(name, image);
		imageNumberInt++;
		sprintf(imageNumberString, "%d", imageNumberInt);
		
		image = imread("Training set/" + name + "/" + imageNumberString + ".jpg");
	}

	Mat a;
	return out;
}
Example #13
0
//-----------------------------------【main( )函数】--------------------------------------------
//		描述:控制台应用程序的入口函数,我们的程序从这里开始
//-------------------------------------------------------------------------------------------------
int main( void )
{
  VideoCapture capture;
  Mat frame;


  //-- 1. 加载级联(cascades)
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

  //-- 2. 读取视频
  capture.open(0);
  ShowHelpText();
  if( capture.isOpened() )
  {
    for(;;)
    {
      capture >> frame;

      //-- 3. 对当前帧使用分类器(Apply the classifier to the frame)
      if( !frame.empty() )
       { detectAndDisplay( frame ); }
      else
       { printf(" --(!) No captured frame -- Break!"); break; }

      int c = waitKey(10);
      if( (char)c == 'c' ) { break; }

    }
  }
  return 0;
}
Example #14
0
/**
 * @function main
 */
int main( void )
{
    VideoCapture capture(0);
    Mat frame;

    //-- 1. Load the cascade
    if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; };
    if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading eyes cascade\n"); return -1; };

    //-- 2. Read the video stream
    capture.open( -1 );
    if ( ! capture.isOpened() ) { printf("--(!)Error opening video capture\n"); return -1; }

    while ( capture.read(frame) )
    {
        if( frame.empty() )
        {
            printf(" --(!) No captured frame -- Break!");
            break;
        }

        //-- 3. Apply the classifier to the frame
        detectAndDisplay( frame );

        //-- bail out if escape was pressed
        int c = waitKey(10);
        if( (char)c == 27 ) { break; }
    }
    return 0;
}
Example #15
0
  void imageCb(const sensor_msgs::ImageConstPtr& msg)
  {
 
  sensor_msgs::CvBridge bridge;//we need this object bridge for facilitating conversion from ros-img to opencv
  IplImage *img = bridge.imgMsgToCv(msg,"bgr8");  //image being converted from ros to opencv using cvbridge

  ros::Publisher chatter_pub = n.advertise<image_process::Positions>("test", 1000);   	

  Mat frame(img);
  //-- 1. Load the cascades
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); };

      //-- 3. Apply the classifier to the frame
      if( !frame.empty() )
       { detectAndDisplay( frame ); }
      else
       { printf(" --(!) No captured frame -- Break!");}

      int c = waitKey(10);
      if( (char)c == 'c' ) { 
	exit(0); 
	}

}
Example #16
0
/*
int main(int argc, char ** argv)
{

	// DIR *dir;
	// // "/home/terry/Desktop/testing/0.jpg"
	// struct dirent *ent;
	// if((dir = opendir(argv[1])) == NULL)
	// {
	// 	perror("");
	// 	return EXIT_FAILURE;
	// }

	if(!faceDetectInit())
	{
		printf("Cannot Init face detector\n");
		return -1;
	}

	while(1)
	{
		// if(strcmp(ent->d_name,".") == 0 || strcmp(ent->d_name,"..") == 0)
		// 	continue;
		// char filename[64];
		// strcpy(filename,argv[1]);
		// strcat(filename,"/");
		// strcat(filename,ent->d_name);
		// printf("Openning %s\n",filename);

		Mat img = imread("/home/terry/Desktop/testing/0.jpg",CV_LOAD_IMAGE_COLOR);
		namedWindow("Face Detection",CV_WINDOW_AUTOSIZE);
		detectAndDisplay(img);
		if(waitKey(0) == 'n')
		{
			continue;
			destroyWindow("Face Detection");
		}
		else
			break;
	}
	return 0;
}
*/
int faceDetectInit()
{
	//-- 1. Load the cascade
	if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; };
	if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading eyes cascade\n"); return -1; };
	return 1;
}
Example #17
0
int main(int argc, const char** argv)
{
	CvCapture* capture = 0;
	Mat image;
	double scale = 1;

	cascade.load(cascadeName);
	nestedCascade.load(nestedCascadeName);



	cvNamedWindow("result", 1);



	image = imread(argv[1], 1);
	if (!image.empty())
	{


		detectAndDraw(image, cascade, nestedCascade, scale);
		cout << endl << " Number of face(s) detected :" << facecounter + 1 << endl;
		waitKey(0);
	}



	cvDestroyWindow("result");

	return 0;
}
Example #18
0
/**
 * @function main
 */
int main( void )
{
  CvCapture* capture;
  Mat frame;

  //-- 1. Load the cascade
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

  //-- 2. Read the video stream
  capture = cvCaptureFromCAM( -1 );
  if( capture )
  {
    for(;;)
    {
      frame = cv::cvarrToMat(cvQueryFrame( capture ));

      //-- 3. Apply the classifier to the frame
      if( !frame.empty() )
       { detectAndDisplay( frame ); }
      else
       { printf(" --(!) No captured frame -- Break!"); break; }

      int c = waitKey(10);
      if( (char)c == 'c' ) { break; }

    }
  }
  return 0;
}
int checkCascadeFile()
{
  //-- 1. Load the cascade
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !mouth_cascade.load( mouth_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !nose_cascade.load( nose_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  return 0;
}
Example #20
0
int main( void )
{
    done = false;
    mode = true;

    SP = new Serial("\\\\.\\COM8");
    if (SP->IsConnected())
        printf("Connected");
    buffer="i";
    SP->WriteData(buffer, 1);
    command = 0;
    Sleep(500);

    //
    VideoCapture capture;
    capture.open(0);
    Mat frame;

    if( !face_cascade.load( face_cascade_name ) )
    {
        printf("--(!)Error loading face cascade\n");
        return -1;
    };
    if( !eyes_cascade.load( eyes_cascade_name ) )
    {
        printf("--(!)Error loading eyes cascade\n");
        return -1;
    };
    if ( ! capture.isOpened() )
    {
        printf("--(!)Error opening video capture\n");
        return -1;
    }
    while ( capture.read(frame) )
    {
        if( frame.empty() )
        {
            printf(" —(!) No captured frame — Break!");
            break;
        }
        detectAndDisplay( frame );
        int c = waitKey(10);
        if( (char)c == 27 )
        {
            break;
        }
    }

    buffer="p";
    SP->WriteData(buffer, 1);
    Sleep(500);

    return 0;
}
Example #21
0
void Init()
{
	string cascadeName = "E:/software/opencv2.4.6.0/data/haarcascades/haarcascade_frontalface_alt.xml";
	string nestedCascadeName = "E:/software/opencv2.4.6.0/data/haarcascades/haarcascade_eye_tree_eyeglasses.xml";
	double scale = 1.0;
	bool tryflip = false;
	if( !cascade.load( cascadeName ) ||!nestedCascade.load( nestedCascadeName))
	{
		cerr << "ERROR: Could not load classifier cascade or nestedCascade" << endl;//若出现该问题请去检查cascadeName,可能是opencv版本路径问题
		return;
	}
}
Example #22
0
int init() {
  if( !nestedCascade.load( NestedCascadeName ) )
      cerr << "WARNING: Could not load classifier cascade for nested objects from path "
           << NestedCascadeName << endl;

  if( !cascade.load( CascadeName ) ) {
      cerr << "ERROR: Could not load classifier cascade from path "
           << CascadeName << endl;
      return -1;
  }
  return 0;
}
Example #23
0
/**
 * @function main
 */
int main( void )
{
    VideoCapture capture;
    Mat frame;
    time_t start,end;
    int counter = 0;
    double sec;
    double fps;

    //-- 1. Load the cascade
    if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; };
    if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading eyes cascade\n"); return -1; };

    //-- 2. Read the video stream
    capture.open( -1 );
    if ( ! capture.isOpened() ) { printf("--(!)Error opening video capture\n"); return -1; }
	capture.set(CV_CAP_PROP_FRAME_WIDTH, 352);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT, 288);

    while ( capture.read(frame) )
    {
        if( frame.empty() )
        {
            printf(" --(!) No captured frame -- Break!");
            break;
        }

        //-- 3. Apply the classifier to the frame
	// fps counter begin
        if (counter == 0){
            time(&start);
        }
	detectAndDisplay(frame);
	// fps counter begin
        time(&end);
        counter++;
        sec = difftime(end, start);
        fps = counter/sec;
        if (counter > 30)
            printf("%.2f fps\n", fps);
        // overflow protection
        if (counter == (INT_MAX - 1000))
            counter = 0;
        // fps counter end

	//-- bail out if escape was pressed
        int c = waitKey(10);
        if( (char)c == 27 ) { break; }
    }
    return 0;
}
Example #24
0
	void checkcascade_load(string checkcascade_string)               //loading the test/check cascade
	{
		checkcascade.load(checkcascade_string);

		if( !checkcascade.load(checkcascade_string) )
    	{
        	cout << endl << "Could not load classifier checkcascade" << endl;
        	
    	}
		else
		{
			cout<< "checkcascade : " << checkcascade_string << " loaded" << endl;
		}
	}
Example #25
0
/**
 * @function main
 */
int main(void)
{
  VideoCapture capture;
  Mat frame;
  Mat face;
  int cont = 0;
  string nome = "diogo";

  //-- 1. Load the cascades
  if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
  if(!profile_cascade.load(profile_cascade_name)){cout << "Error on loading Profile Cascade"; return -1; };
  //-- 2. Read the video stream
  capture.open(-1);
  if( capture.isOpened())
  {
    for(;;)
    {
      capture >> frame;
      //-- 3. Apply the classifier to the frame
      if(!frame.empty()){
		  face = detectAndDisplay(frame);
		  
		 /* if(cont == 0)
		  {
			cout << "Hello, I'm Bill what is your name?" << endl;
			cin >> nome;  
		  }*/
		  if(cont < 10)
		  {
			  //grava a pessoa
			  recordPerson(nome, face, cont);
			  cont++;
	      }else if(cont == 10){
			  cout << "Thanks. Now i know you, see you later!" << endl;
		  }
	  }
      else
      {
		  printf(" --(!) No captured frame -- Break!"); 
		  break; 
      }

      int c = waitKey(10);
      if( (char)c == 'c' ) { break; }
    }
  }
  return 0;
}
int main() {

  VideoCapture cap(0); // Open default camera
  Mat frame;

  face_cascade.load("haarcascade_frontalface_alt.xml"); // load faces
  eyes_cascade.load("haarcascade_eye_tree_eyeglasses.xml"); // load eyes

  while(cap.read(frame)) {
    detectFaces(frame); // Call function to detect faces
    if( waitKey(30) >= 0)    // pause
      break;
  }
  return 0;
}
Example #27
0
int main()
{
	key_t key;
	int shmid;

	if( !face_cascade.load( face_cascade_name ) ){
            printf("load wrong!\n");
	    exit(1);
        }
	//sleep(1);
	key=ftok("/tmp/a",'a');
	shmid=shmget(key,640*480*3,IPC_CREAT|0666);
	if(shmid<0)
		{
			printf("get share memory wrong!\n");
			exit(0);
		}
	buffer =(char *)shmat(shmid,0,0);
		if(buffer==NULL)
		{
			printf("map share memory wrong!\n");
			exit(0);
		}
	ppid = getppid();
	//printf("ppid:%d\n",ppid);
	signal(SIGUSR1,detection);
	while(1)
	{
	  pause();
	}
	return 0;
}
/** @function detectAndDisplay */
void detectFace( Mat frame )
{
  std::vector<Rect> faces;
  Mat frame_gray;

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

  CascadeClassifier face_cascade;
  face_cascade.load( "haarcascade_frontalface_alt.xml" );
    
  //-- Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 3, 0|CV_HAAR_SCALE_IMAGE, Size(15, 15) );

  for( size_t 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( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

    Mat faceROI = frame_gray( faces[i] );
    std::vector<Rect> eyes;

   /* //-- In each face, detect eyes
    eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );

    for( size_t j = 0; j < eyes.size(); j++ )
     {
       Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
       int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
       circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
     }*/
  }
  //-- Show o/p
  //imshow( window_name, frame );
 }
Example #29
0
int main( int argc, const char** argv )
{
    CvCapture* capture;
    Mat frame;

    if( !face_cascade.load( face_cascade_name ) ) {
        std::cerr << "ERROR: could not load "<< face_cascade_name << "\n";
        return -1;
    };

    capture = cvCaptureFromCAM(0);
    if( capture )
    {
        cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,frameWidth);
        cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,frameHeight);
        while( true )
        {
            frame = cvQueryFrame( capture );

            if( !frame.empty() ) {
                detectAndDisplay( frame );
            } else {
                std::cerr<< "ERROR: empty frame!\n";
                break;
            }

            int c = waitKey(1);
            if( (char)c == 'c' ) {
                break;
            }
        }
    }
    return 0;
}
Example #30
0
	void cascade_load(string cascade_string)            
	{
		cascade.load(cascade_string);

		if( !cascade.load(cascade_string) )
    	{
        	cout << endl << "Could not load classifier cascade" << endl;
        	
    	}
		else
		{
			
			cout << "cascade : " << cascade_string << " loaded" << endl;
		}

	}