34 rhs[1] =
MxArray(image_.getMat());
38 bool success = (
mexCallMATLAB(1, &lhs, 2, rhs,
"feval") == 0);
60 return FacemarkAAM::Config(
63 arr.
isField(
"scale") ? arr.
at(
"scale", idx).toFloat() : 1.0f,
64 arr.
isField(
"scaleIdx") ? arr.
at(
"scaleIdx", idx).toInt() : 0
85 "MxArray unable to convert to std::vector<cv::face::FacemarkAAM::Config>");
101 for (; first != last; first += 2) {
102 string key(first->toString());
103 const MxArray& val = *(first + 1);
104 if (key ==
"ShapeOffset")
106 else if (key ==
"CascadeFace")
108 else if (key ==
"Verbose")
109 parameters.
verbose = val.toBool();
110 else if (key ==
"NLandmarks")
112 else if (key ==
"InitShapeN")
114 else if (key ==
"StagesN")
116 else if (key ==
"TreeN")
117 parameters.
tree_n = val.toInt();
118 else if (key ==
"TreeDepth")
120 else if (key ==
"BaggingOverlap")
122 else if (key ==
"ModelFilename")
124 else if (key ==
"SaveModel")
126 else if (key ==
"Seed")
127 parameters.
seed =
static_cast<unsigned>(val.toInt());
128 else if (key ==
"FeatsM")
129 parameters.
feats_m = val.toVector<
int>();
130 else if (key ==
"RadiusM")
131 parameters.
radius_m = val.toVector<
double>();
132 else if (key ==
"Pupils") {
133 if (!val.isCell() || val.numel() != 2)
136 parameters.
pupils[0] = arr[0].toVector<
int>();
137 parameters.
pupils[1] = arr[1].toVector<
int>();
139 else if (key ==
"DetectROI")
143 "Unrecognized option %s", key.c_str());
160 for (; first != last; first += 2) {
161 string key(first->toString());
162 const MxArray& val = *(first + 1);
163 if (key ==
"ModelFilename")
166 parameters.
m = val.toInt();
168 parameters.
n = val.toInt();
169 else if (key ==
"NIter")
170 parameters.
n_iter = val.toInt();
171 else if (key ==
"Verbose")
172 parameters.
verbose = val.toBool();
173 else if (key ==
"SaveModel")
175 else if (key ==
"MaxM")
176 parameters.
max_m = val.toInt();
177 else if (key ==
"MaxN")
178 parameters.
max_n = val.toInt();
179 else if (key ==
"TextureMaxM")
181 else if (key ==
"Scales")
182 parameters.
scales = val.toVector<
float>();
185 "Unrecognized option %s", key.c_str());
206 else if (
type ==
"AAM")
210 "Unrecognized facemark %s",
type.c_str());
231 int id = rhs[0].toInt();
232 func = rhs[1].toString();
233 string method(rhs[2].toString());
236 if (method ==
"new") {
239 rhs[3].toString(), rhs.
begin() + 4, rhs.
end());
245 else if (method ==
"getFacesHAAR") {
248 string face_cascade_name(rhs[4].toString());
256 else if (method ==
"loadDatasetList") {
258 string imageList(rhs[3].toString());
259 string annotationList(rhs[4].toString());
262 imageList, annotationList, images, annotations);
265 plhs[1] =
MxArray(annotations);
270 else if (method ==
"loadTrainingData1") {
271 nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=3);
273 for (
int i=5; i<nrhs; i+=2) {
274 string key(rhs[i].toString());
276 offset = rhs[i+1].toFloat();
279 "Unrecognized option %s", key.
c_str());
281 string imageList(rhs[3].toString());
282 string groundTruth(rhs[4].toString());
286 imageList, groundTruth, images, facePoints, offset);
294 else if (method ==
"loadTrainingData2") {
295 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=3);
298 for (
int i=4; i<nrhs; i+=2) {
299 string key(rhs[i].toString());
301 delim = (!rhs[i+1].isEmpty()) ? rhs[i+1].toString()[0] :
' ';
302 else if (key ==
"Offset")
303 offset = rhs[i+1].toFloat();
306 "Unrecognized option %s", key.
c_str());
308 string filename(rhs[3].toString());
312 filename, images, facePoints, delim, offset);
320 else if (method ==
"loadTrainingData3") {
327 trainlandmarks, trainimages);
328 plhs[0] =
MxArray(trainlandmarks);
330 plhs[1] =
MxArray(trainimages);
335 else if (method ==
"loadFacePoints") {
336 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
338 for (
int i=4; i<nrhs; i+=2) {
339 string key(rhs[i].toString());
341 offset = rhs[i+1].toFloat();
344 "Unrecognized option %s", key.
c_str());
346 string filename(rhs[3].toString());
354 else if (method ==
"drawFacemarks") {
355 nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=1);
357 for (
int i=5; i<nrhs; i+=2) {
358 string key(rhs[i].toString());
360 color = rhs[i+1].toScalar();
363 "Unrecognized option %s", key.
c_str());
376 if (method ==
"delete") {
381 else if (method ==
"clear") {
385 else if (method ==
"empty") {
389 else if (method ==
"getDefaultName") {
393 else if (method ==
"read") {
394 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs==0);
396 bool loadFromString =
false;
397 for (
int i=4; i<nrhs; i+=2) {
398 string key(rhs[i].toString());
399 if (key ==
"ObjName")
400 objname = rhs[i+1].toString();
401 else if (key ==
"FromString")
402 loadFromString = rhs[i+1].toBool();
405 "Unrecognized option %s", key.
c_str());
407 FileStorage fs(rhs[3].toString(), FileStorage::READ +
408 (loadFromString ? FileStorage::MEMORY : 0));
416 else if (method ==
"write") {
418 FileStorage fs(rhs[3].toString(), FileStorage::WRITE +
419 ((nlhs > 0) ? FileStorage::MEMORY : 0));
428 else if (method ==
"addTrainingSample") {
435 else if (method ==
"training") {
439 else if (method ==
"loadModel") {
441 string model(rhs[3].toString());
444 else if (method ==
"fit") {
445 nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=2);
447 for (
int i=5; i<nrhs; i+=2) {
448 string key(rhs[i].toString());
449 if (key ==
"Configs")
453 "Unrecognized option %s", key.
c_str());
458 bool b = obj->
fit(image, faces, landmarks,
459 !configs.
empty() ? &configs : NULL);
464 else if (method ==
"setFaceDetector") {
466 func = rhs[3].toString();
470 else if (method ==
"getFaces") {
474 bool b = obj->
getFaces(image, faces);
479 else if (method ==
"getData") {
485 FacemarkAAM::Data items;
499 "Unrecognized operation %s", method.
c_str());
std::vector< int > feats_m
mwSize numel() const
Number of elements in an array.
T at(mwIndex index) const
Template for numeric array element accessor.
virtual void training(void *parameters=0)=0
void copyTo(OutputArray m) const
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual bool getData(void *items=0)=0
bool loadTrainingData(String filename, std::vector< String > &images, OutputArray facePoints, char delim=' ', float offset=0.0f)
Ptr< FacemarkAAM > createFacemarkAAM(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FacemarkAAM using options in arguments.
int last_id
Last object id to allocate.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C void mxDestroyArray(mxArray *pa)
mxArray destructor
virtual bool isOpened() const
Ptr< FacemarkLBF > createFacemarkLBF(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of FacemarkLBF using options in arguments.
struct mxArray_tag mxArray
Forward declaration for mxArray.
vector< FacemarkAAM::Config > MxArrayToVectorConfig(const MxArray &arr)
Convert an MxArray to std::vector<cv::face::FacemarkAAM::Config>
virtual bool fit(InputArray image, InputArray faces, InputOutputArray landmarks, void *config=0)=0
string func
name of MATLAB function to evaluate (custom face detector)
virtual String releaseAndGetString()
Ptr< Y > dynamicCast() const
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
std::vector< int > pupils[2]
bool isCell() const
Determine whether input is cell array.
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
bool getFacesHAAR(InputArray image, OutputArray faces, const String &face_cascade_name)
virtual bool setFaceDetector(FN_FaceDetector detector, void *userData=0)=0
bool loadDatasetList(String imageList, String annotationList, std::vector< String > &images, std::vector< String > &annotations)
bool isField(const std::string &fieldName) const
Determine whether a struct array has a specified field.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
CV__DEBUG_NS_END typedef const _InputArray & InputArray
bool matlab_face_detector(InputArray image_, OutputArray faces_, void *userData)
Custom face detector implemented as a MATLAB function.
FileNode getFirstTopLevelNode() const
bool isStruct() const
Determine whether input is structure array.
map< int, Ptr< Facemark > > obj_
Object container.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
FacemarkAAM::Config MxArrayToConfig(const MxArray &arr, mwIndex idx=0)
Convert an MxArray to cv::face::FacemarkAAM::Config.
virtual String getDefaultName() const
Global constant definitions.
std::string model_filename
virtual void write(FileStorage &fs) const=0
virtual bool getFaces(InputArray image, OutputArray faces)=0
Ptr< Facemark > createFacemark(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of Facemark using options in arguments.
std::vector< float > scales
bool loadFacePoints(String filename, OutputArray points, float offset=0.0f)
std::string model_filename
virtual bool empty() const
virtual void loadModel(String model)=0
void drawFacemarks(InputOutputArray image, InputArray points, Scalar color=Scalar(255, 0, 0))
std::vector< double > radius_m
LIBMWMEX_API_EXTERN_C int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[], const char *fcn_name)
call MATLAB function
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
virtual void read(const FileNode &fn)=0
virtual bool addTrainingSample(InputArray image, InputArray landmarks)=0