当前位置: 首页>>代码示例>>C++>>正文


C++ People::detectAllFaces方法代码示例

本文整理汇总了C++中People::detectAllFaces方法的典型用法代码示例。如果您正苦于以下问题:C++ People::detectAllFaces方法的具体用法?C++ People::detectAllFaces怎么用?C++ People::detectAllFaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在People的用法示例。


在下文中一共展示了People::detectAllFaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: image_cb_all

  /// The image callback. For each new image, copy it, perform face detection, and draw the rectangles on the image.
  void image_cb_all(ros::Time t)
  {

    detect_++;
    if (detect_ % 2) {
      return;
    }

    cv_mutex_.lock();
 
    CvSize im_size;

    // Convert the images to OpenCV format
    if (lbridge_.fromImage(limage_,"bgr")) {
      cv_image_left_ = lbridge_.toIpl();
    }
    if (dbridge_.fromImage(dimage_)) {
      cv_image_disp_ = dbridge_.toIpl();
    }

    // Convert the stereo calibration into a camera model.
    if (cam_model_) {
      delete cam_model_;
    }
    double Fx = rcinfo_.P[0];
    double Fy = rcinfo_.P[5];
    double Clx = rcinfo_.P[2];
    double Crx = Clx;
    double Cy = rcinfo_.P[6];
    double Tx = -rcinfo_.P[3]/Fx;
    cam_model_ = new CvStereoCamModel(Fx,Fy,Tx,Clx,Crx,Cy,1.0/(double)stinfo_.dpp);
 
    if ( cv_image_left_ )  {
      im_size = cvGetSize(cv_image_left_);
      vector<CvRect> faces_vector = people_->detectAllFaces(cv_image_left_, haar_filename_, 1.0, cv_image_disp_, cam_model_, true);

      // Get the average disparity in the middle half of the bounding box, and compute the face center in 3d. 
      // Publish the face center as a track point.
      if (cv_image_disp_ && cam_model_) {
	int r, c, good_pix;
	ushort* ptr;
	double avg_disp;
	CvRect *one_face;
	robot_msgs::PositionMeasurement pos;
	CvMat *uvd = cvCreateMat(1,3,CV_32FC1);
	CvMat *xyz = cvCreateMat(1,3,CV_32FC1);
	for (uint iface = 0; iface < faces_vector.size(); iface++) {
	  one_face = &faces_vector[iface];
	  good_pix = 0;
	  avg_disp = 0;
	  for (r = floor(one_face->y+0.25*one_face->height); r < floor(one_face->y+0.75*one_face->height); r++) {
	    ptr = (ushort*)(cv_image_disp_->imageData + r*cv_image_disp_->widthStep);
	    for (c = floor(one_face->x+0.25*one_face->width); c < floor(one_face->x+0.75*one_face->width); c++) {
	      if (ptr[c] > 0) {
		avg_disp += ptr[c];
		good_pix++;
	      }
	    }
	  }
	  avg_disp /= (double)good_pix; // Take the average.
	  cvmSet(uvd,0,0,one_face->x+one_face->width/2.0);
	  cvmSet(uvd,0,1,one_face->y+one_face->height/2.0);
	  cvmSet(uvd,0,2,avg_disp);
	  cam_model_->dispToCart(uvd,xyz);
	  
	  bool do_publish = true;
	  if (external_init_) {
	    // Check if this person's face is close enough to one of the previously known faces and associate it.
	    // If not, don't publish it.
	  }

	  if (do_publish) {
	    pos.header.stamp = limage_.header.stamp;
	    pos.name = "face_detection";
	    pos.object_id = "-1";
	    pos.pos.x = cvmGet(xyz,0,2);
	    pos.pos.y = -1.0*cvmGet(xyz,0,0);
	    pos.pos.z = -1.0*cvmGet(xyz,0,1);
	    pos.header.frame_id = "stereo_link";
	    pos.reliability = 0.8;
	    pos.initialization = 0;
	    //pos.covariance = ;
	    publish("person_measurement",pos);
	  }
	}

	cvReleaseMat(&uvd);
	cvReleaseMat(&xyz);	
      
	if (do_display_) {
	  if (!cv_image_disp_out_) {
	    cv_image_disp_out_ = cvCreateImage(im_size,IPL_DEPTH_8U,1);
	  }
	  cvCvtScale(cv_image_disp_,cv_image_disp_out_,4.0/stinfo_.dpp);

	  cvShowImage("Face detector: Face Detection",cv_image_left_);
	  cvShowImage("Face detector: Disparity",cv_image_disp_out_);
	}
      }
//.........这里部分代码省略.........
开发者ID:janfrs,项目名称:kwc-ros-pkg,代码行数:101,代码来源:face_detection.cpp


注:本文中的People::detectAllFaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。