FaceDescriptor FeatureDetectorTask::operator()() {
  FaceDescriptor descriptor;
  if(faceDetector && featureDetector && !image.empty()) {
    descriptor.faceBounds = faceDetector->Detect(image);
    cv::Rect faceRegion = descriptor.faceBounds;

    // Left eye
    cv::Rect leftEyeRegion(faceRegion.x, faceRegion.y,
                           faceRegion.width / 2, faceRegion.height * 2 / 3);
    if(leftEyeRegion.area()) {
      descriptor.leftEye = featureDetector->LocateLeftEye(image(leftEyeRegion));
    }
    
    //Right eye
    cv::Rect rightEyeRegion(faceRegion.x + faceRegion.width / 2, faceRegion.y,
                            faceRegion.width / 2, faceRegion.height * 2 / 3);
    if(rightEyeRegion.area()) {
      descriptor.rightEye = featureDetector->LocateLeftEye(image(rightEyeRegion)) +
        cv::Point(faceRegion.width / 2, 0);
    }
      
    cv::Rect mouthRegion(faceRegion.x, faceRegion.y + faceRegion.height / 2,
                       faceRegion.width, faceRegion.height / 2);
    if(mouthRegion.area()) {
      descriptor.mouth = featureDetector->LocateMouth(image(mouthRegion)) +
        cv::Point(0, faceRegion.height / 2); 
    }
    // descriptor.nose = featureDetector->LocateNose(face); 
  }
  return descriptor;
}
Exemplo n.º 2
0
void findEyes(cv::Mat frame_gray, cv::Rect face, Point& leftPupil, Point& rightPupil) {
  cv::Mat faceROI = frame_gray(face);

  if (kSmoothFaceImage) {
    double sigma = kSmoothFaceFactor * face.width;
    GaussianBlur( faceROI, faceROI, cv::Size( 0, 0 ), sigma);
  }
  //-- Find eye regions and draw them
  int eye_region_width = face.width * (kEyePercentWidth/100.0);
  int eye_region_height = face.width * (kEyePercentHeight/100.0);
  int eye_region_top = face.height * (kEyePercentTop/100.0);
  cv::Rect leftEyeRegion(face.width*(kEyePercentSide/100.0),
                         eye_region_top,eye_region_width,eye_region_height);
  cv::Rect rightEyeRegion(face.width - eye_region_width - face.width*(kEyePercentSide/100.0),
                          eye_region_top,eye_region_width,eye_region_height);

  //-- Find Eye Centers
  leftPupil = findEyeCenterMat(faceROI,leftEyeRegion);
  rightPupil = findEyeCenterMat(faceROI,rightEyeRegion);

  rightPupil.x += rightEyeRegion.x + face.x;
  rightPupil.y += rightEyeRegion.y + face.y;
  leftPupil.x += leftEyeRegion.x + face.x;
  leftPupil.y += leftEyeRegion.y + face.y;

}
Exemplo n.º 3
0
void findEyes(cv::Mat frame_gray, cv::Rect face) {
  cv::Mat faceROI = frame_gray(face);
  
  if (kSmoothFaceImage) {
    double sigma = kSmoothFaceFactor * face.width;
    GaussianBlur( faceROI, faceROI, cv::Size( 0, 0 ), sigma);
  }
  //-- Find eye regions and draw them
  int eye_region_width = face.width * (kEyePercentWidth/100.0);
  int eye_region_height = face.width * (kEyePercentHeight/100.0);
  int eye_region_top = face.height * (kEyePercentTop/100.0);
  cv::Rect leftEyeRegion(face.width*(kEyePercentSide/100.0),
                         eye_region_top,eye_region_width,eye_region_height);
  cv::Rect rightEyeRegion(face.width - eye_region_width - face.width*(kEyePercentSide/100.0),
                          eye_region_top,eye_region_width,eye_region_height);
  
  //-- Find Eye Centers
  cv::Point leftPupil = findEyeCenter(faceROI,leftEyeRegion,"Left Eye");
  cv::Point rightPupil = findEyeCenter(faceROI,rightEyeRegion,"Right Eye");
  // get corner regions
  cv::Rect leftCornerRegion(leftEyeRegion);
  leftCornerRegion.width -= leftPupil.x;
  leftCornerRegion.x += leftPupil.x;
  leftCornerRegion.height /= 2;
  leftCornerRegion.y += leftCornerRegion.height / 2;
  cv::Rect rightCornerRegion(rightEyeRegion);
  rightCornerRegion.width = rightPupil.x;
  rightCornerRegion.height /= 2;
  rightCornerRegion.y += rightCornerRegion.height / 2;
  rectangle(faceROI,leftCornerRegion,200);
  rectangle(faceROI,rightCornerRegion,200);
  // change eye centers to face coordinates
  rightPupil.x += rightEyeRegion.x;
  rightPupil.y += rightEyeRegion.y;
  leftPupil.x += leftEyeRegion.x;
  leftPupil.y += leftEyeRegion.y;
  // draw eye centers
  circle(faceROI, rightPupil, 3, 1234);
  circle(faceROI, leftPupil, 3, 1234);
  
  //-- Find Eye Corners
  if (kEnableEyeCorner) {
    cv::Point leftCorner = findEyeCorner(faceROI(leftCornerRegion), false);
    leftCorner.x += leftCornerRegion.x;
    leftCorner.y += leftCornerRegion.y;
    cv::Point rightCorner = findEyeCorner(faceROI(leftCornerRegion), false);
    rightCorner.x += rightCornerRegion.x;
    rightCorner.y += rightCornerRegion.y;
    circle(faceROI, rightCorner, 3, 200);
    circle(faceROI, leftCorner, 3, 200);
  }
  
  imshow(face_window_name, faceROI);
}