Commit 4df17e67 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #2069 from tegusi:landmark_fix

parents ffd13f92 5101dcc4
...@@ -74,8 +74,8 @@ public: ...@@ -74,8 +74,8 @@ public:
@endcode @endcode
*/ */
CV_WRAP virtual bool fit( InputArray image, CV_WRAP virtual bool fit( InputArray image,
InputArray faces, const std::vector<Rect>& faces,
OutputArrayOfArrays landmarks ) = 0; CV_OUT std::vector<std::vector<Point2f> >& landmarks ) = 0;
}; /* Facemark*/ }; /* Facemark*/
......
...@@ -146,7 +146,7 @@ public: ...@@ -146,7 +146,7 @@ public:
}; };
//! overload with additional Config structures //! overload with additional Config structures
virtual bool fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &runtime_params ) = 0; virtual bool fitConfig( InputArray image, const std::vector<Rect>& roi, std::vector<std::vector<Point2f> >& _landmarks, const std::vector<Config> &runtime_params ) = 0;
//! initializer //! initializer
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
void loadModel(String fs) CV_OVERRIDE; void loadModel(String fs) CV_OVERRIDE;
bool setFaceDetector(FN_FaceDetector f, void* userdata) CV_OVERRIDE; bool setFaceDetector(FN_FaceDetector f, void* userdata) CV_OVERRIDE;
bool getFaces(InputArray image, OutputArray faces) CV_OVERRIDE; bool getFaces(InputArray image, OutputArray faces) CV_OVERRIDE;
bool fit(InputArray image, InputArray faces, OutputArrayOfArrays landmarks ) CV_OVERRIDE; bool fit(InputArray image, const std::vector<Rect>& faces, CV_OUT std::vector<std::vector<Point2f> >& landmarks ) CV_OVERRIDE;
void training(String imageList, String groundTruth); void training(String imageList, String groundTruth);
bool training(vector<Mat>& images, vector< vector<Point2f> >& landmarks,string filename,Size scale,string modelFilename) CV_OVERRIDE; bool training(vector<Mat>& images, vector< vector<Point2f> >& landmarks,string filename,Size scale,string modelFilename) CV_OVERRIDE;
// Destructor for the class. // Destructor for the class.
......
...@@ -103,12 +103,11 @@ public: ...@@ -103,12 +103,11 @@ public:
bool getData(void * items) CV_OVERRIDE; bool getData(void * items) CV_OVERRIDE;
bool fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &runtime_params ) CV_OVERRIDE; bool fitConfig( InputArray image, const std::vector<Rect>& roi, std::vector<std::vector<Point2f> >& _landmarks, const std::vector<Config> &runtime_params ) CV_OVERRIDE;
protected: protected:
bool fit( InputArray image, InputArray faces, OutputArrayOfArrays landmarks ) CV_OVERRIDE; bool fit( InputArray image, const std::vector<Rect>& faces, CV_OUT std::vector<std::vector<Point2f> >& landmarks ) CV_OVERRIDE;
//bool fit( InputArray image, InputArray faces, InputOutputArray landmarks, void * runtime_params);//!< from many ROIs
bool fitImpl( const Mat image, std::vector<Point2f>& landmarks,const Mat R,const Point2f T,const float scale, const int sclIdx=0 ); bool fitImpl( const Mat image, std::vector<Point2f>& landmarks,const Mat R,const Point2f T,const float scale, const int sclIdx=0 );
bool addTrainingSample(InputArray image, InputArray landmarks) CV_OVERRIDE; bool addTrainingSample(InputArray image, InputArray landmarks) CV_OVERRIDE;
...@@ -323,19 +322,18 @@ void FacemarkAAMImpl::training(void* parameters){ ...@@ -323,19 +322,18 @@ void FacemarkAAMImpl::training(void* parameters){
if(params.verbose) printf("Training is completed\n"); if(params.verbose) printf("Training is completed\n");
} }
bool FacemarkAAMImpl::fit( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks ) bool FacemarkAAMImpl::fit( InputArray image, const std::vector<Rect>& roi, CV_OUT std::vector<std::vector<Point2f> >& _landmarks )
{ {
std::vector<Config> config; // empty std::vector<Config> config; // empty
return fitConfig(image, roi, _landmarks, config); return fitConfig(image, roi, _landmarks, config);
} }
bool FacemarkAAMImpl::fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &configs ) bool FacemarkAAMImpl::fitConfig( InputArray image, const std::vector<Rect>& roi, std::vector<std::vector<Point2f> >& _landmarks, const std::vector<Config> &configs )
{ {
std::vector<Rect> & faces = *(std::vector<Rect> *)roi.getObj(); const std::vector<Rect> & faces = roi;
if(faces.size()<1) return false; if(faces.size()<1) return false;
std::vector<std::vector<Point2f> > & landmarks = std::vector<std::vector<Point2f> > & landmarks = _landmarks;
*(std::vector<std::vector<Point2f> >*) _landmarks.getObj();
landmarks.resize(faces.size()); landmarks.resize(faces.size());
Mat img = image.getMat(); Mat img = image.getMat();
......
...@@ -115,7 +115,7 @@ public: ...@@ -115,7 +115,7 @@ public:
protected: protected:
bool fit( InputArray image, InputArray faces, OutputArrayOfArrays landmarks ) CV_OVERRIDE;//!< from many ROIs bool fit( InputArray image, const std::vector<Rect> & faces, std::vector<std::vector<Point2f> > & landmarks ) CV_OVERRIDE;//!< from many ROIs
bool fitImpl( const Mat image, std::vector<Point2f> & landmarks );//!< from a face bool fitImpl( const Mat image, std::vector<Point2f> & landmarks );//!< from a face
bool addTrainingSample(InputArray image, InputArray landmarks) CV_OVERRIDE; bool addTrainingSample(InputArray image, InputArray landmarks) CV_OVERRIDE;
...@@ -370,14 +370,12 @@ void FacemarkLBFImpl::training(void* parameters){ ...@@ -370,14 +370,12 @@ void FacemarkLBFImpl::training(void* parameters){
isModelTrained = true; isModelTrained = true;
} }
bool FacemarkLBFImpl::fit( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks ) bool FacemarkLBFImpl::fit( InputArray image, const std::vector<Rect> & roi, CV_OUT std::vector<std::vector<Point2f> > & _landmarks )
{ {
// FIXIT const std::vector<Rect> & faces = roi;
std::vector<Rect> & faces = *(std::vector<Rect> *)roi.getObj();
if (faces.empty()) return false; if (faces.empty()) return false;
std::vector<std::vector<Point2f> > & landmarks = std::vector<std::vector<Point2f> > & landmarks = _landmarks;
*(std::vector<std::vector<Point2f> >*) _landmarks.getObj();
landmarks.resize(faces.size()); landmarks.resize(faces.size());
......
...@@ -168,15 +168,15 @@ void FacemarkKazemiImpl :: loadModel(String filename){ ...@@ -168,15 +168,15 @@ void FacemarkKazemiImpl :: loadModel(String filename){
f.close(); f.close();
isModelLoaded = true; isModelLoaded = true;
} }
bool FacemarkKazemiImpl::fit(InputArray img, InputArray roi, OutputArrayOfArrays landmarks){ bool FacemarkKazemiImpl::fit(InputArray img, const std::vector<Rect>& roi, CV_OUT std::vector<std::vector<Point2f> >& landmarks){
if(!isModelLoaded){ if(!isModelLoaded){
String error_message = "No model loaded. Aborting...."; String error_message = "No model loaded. Aborting....";
CV_Error(Error::StsBadArg, error_message); CV_Error(Error::StsBadArg, error_message);
return false; return false;
} }
Mat image = img.getMat(); Mat image = img.getMat();
std::vector<Rect> & faces = *(std::vector<Rect>*)roi.getObj(); const std::vector<Rect> & faces = roi;
std::vector<std::vector<Point2f> > & shapes = *(std::vector<std::vector<Point2f> >*) landmarks.getObj(); std::vector<std::vector<Point2f> > & shapes = landmarks;
shapes.resize(faces.size()); shapes.resize(faces.size());
if(image.empty()){ if(image.empty()){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment