How to find the model files for facemark->load model of OpenCV_Contrib?

841 Views Asked by At
bool myDetector(cv::InputArray image, cv::OutputArray faces, cv::CascadeClassifier *face_cascade){
  cv::Mat gray;

  if (image.channels() > 1)
    cvtColor(image, gray, CV_BGR2GRAY);
  else
    gray = image.getMat().clone();

  equalizeHist(gray, gray);

  std::vectorcv::Rect faces_;
  face_cascade->detectMultiScale(gray, faces_, 1.4, 2, cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30));
  cv::Mat(faces_).copyTo(faces);
  return true;
}

(UIImage *) detectFacialLandmark:(UIImage *) image{
  double CurrentTime = CACurrentMediaTime();

  NSString *pathToFaceCascade = [[NSBundle mainBundle] pathForResource:@"lbpcascade_frontalface" ofType:@"xml"];

  cv::Mat faceImage;
  UIImageToMat(image, faceImage);

  cv::CascadeClassifier face_cascade;
  face_cascade.load([pathToFaceCascade UTF8String]);
  cv::face::FacemarkKazemi::Params params;
  cv::Ptrcv::face::FacemarkKazemi facemark = cv::face::FacemarkKazemi::create(params);
  facemark->setFaceDetector((cv::face::FN_FaceDetector)myDetector, &face_cascade);
  facemark->loadModel("load model");
  std::vectorcv::Rect faces;
  resize(faceImage,faceImage,cv::Size(460,460), 0, 0, cv::INTER_LINEAR_EXACT);
  facemark->getFaces(faceImage,faces);
  std::vector< std::vectorcv::Point2f > shapes;
  if(facemark->fit(faceImage,faces,shapes))
  {
    for( size_t i = 0; i < faces.size(); i++ )
    {
      cv::rectangle(faceImage, faces[i], cvScalar(255, 0, 0));
    }
    for(unsigned long i=0;i<faces.size();i++){
      for(unsigned long k=0;k<shapes[i].size();k++)
        cv::circle(faceImage,shapes[i][k],5,cv::Scalar(0,0,255),cv::FILLED);
    }
  }

  UIImage *returnImage = MatToUIImage(faceImage);
  NSLog(@"test processing time : %f", (CACurrentMediaTime() - CurrentTime));

        return returnImage;
}    

I'm doing the project for the iOS application. For this project, I'm using OpenCV. Specifically, I added OpenCV_contrib modules to obtain the information of face landmarks.

During applied OpenCV_contrib, I have met one problem. facemark->loadModel("load model"); For detecting the facemark, I have to find the model files.

I wonder that how can I find the model files for "facemark->loadModel("load model"); "

2

There are 2 best solutions below

0
On

I don't know how did you install your OpenCV. But to find the data of OpenCV, just go to opencv-master/data if you downloaded, of go to https://github.com/opencv/opencv/tree/master/data to download.

Here is the file list for OpenCV 3.3:

# https://github.com/opencv/opencv/tree/master/data
/opencv-master/data$ tree .
.
├── CMakeLists.txt
├── haarcascades
│   ├── haarcascade_eye_tree_eyeglasses.xml
│   ├── haarcascade_eye.xml
│   ├── haarcascade_frontalcatface_extended.xml
│   ├── haarcascade_frontalcatface.xml
│   ├── haarcascade_frontalface_alt2.xml
│   ├── haarcascade_frontalface_alt_tree.xml
│   ├── haarcascade_frontalface_alt.xml
│   ├── haarcascade_frontalface_default.xml
│   ├── haarcascade_fullbody.xml
│   ├── haarcascade_lefteye_2splits.xml
│   ├── haarcascade_licence_plate_rus_16stages.xml
│   ├── haarcascade_lowerbody.xml
│   ├── haarcascade_profileface.xml
│   ├── haarcascade_righteye_2splits.xml
│   ├── haarcascade_russian_plate_number.xml
│   ├── haarcascade_smile.xml
│   └── haarcascade_upperbody.xml
├── haarcascades_cuda
│   ├── haarcascade_eye_tree_eyeglasses.xml
│   ├── haarcascade_eye.xml
│   ├── haarcascade_frontalface_alt2.xml
│   ├── haarcascade_frontalface_alt_tree.xml
│   ├── haarcascade_frontalface_alt.xml
│   ├── haarcascade_frontalface_default.xml
│   ├── haarcascade_fullbody.xml
│   ├── haarcascade_lefteye_2splits.xml
│   ├── haarcascade_lowerbody.xml
│   ├── haarcascade_profileface.xml
│   ├── haarcascade_righteye_2splits.xml
│   ├── haarcascade_smile.xml
│   └── haarcascade_upperbody.xml
├── hogcascades
│   └── hogcascade_pedestrians.xml
├── lbpcascades
│   ├── lbpcascade_frontalcatface.xml
│   ├── lbpcascade_frontalface_improved.xml
│   ├── lbpcascade_frontalface.xml
│   ├── lbpcascade_profileface.xml
│   └── lbpcascade_silverware.xml
├── readme.txt
└── vec_files
    └── trainingfaces_24-24.vec

5 directories, 39 files
0
On

Here you can find the pretrained lbf model, you can also load your own models. https://github.com/kurnianggoro/GSOC2017/tree/master/data