38 for (; first != last; first += 2) {
39 string key(first->toString());
40 const MxArray& val = *(first + 1);
43 else if (key ==
"Neighbors")
44 neighbors = val.toInt();
45 else if (key ==
"GridX")
47 else if (key ==
"GridY")
49 else if (key ==
"Threshold")
53 "Unrecognized option %s", key.c_str());
56 radius, neighbors, grid_x, grid_y,
threshold);
65 const char *fields[] = {
"label",
"distance"};
67 for (
mwIndex i = 0; i < results.size(); ++i) {
68 s.
set(
"label", results[i].first, i);
69 s.
set(
"distance", results[i].second, i);
89 int id = rhs[0].toInt();
90 string method(rhs[1].toString());
93 if (method ==
"new") {
106 if (method ==
"delete") {
111 else if (method ==
"typeid") {
113 plhs[0] =
MxArray(
string(
typeid(*obj).name()));
115 else if (method ==
"clear") {
119 else if (method ==
"read") {
120 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
121 bool loadFromString =
false;
122 for (
int i=3; i<nrhs; i+=2) {
123 string key(rhs[i].toString());
124 if (key ==
"FromString")
125 loadFromString = rhs[i+1].toBool();
128 "Unrecognized option %s", key.
c_str());
130 string fname(rhs[2].toString());
131 if (loadFromString) {
132 FileStorage fs(fname, FileStorage::READ + FileStorage::MEMORY);
140 else if (method ==
"write") {
142 string fname(rhs[2].toString());
145 FileStorage fs(fname, FileStorage::WRITE + FileStorage::MEMORY);
157 else if (method ==
"empty") {
161 else if (method ==
"getDefaultName") {
165 else if (method ==
"train") {
169 obj->
train(src, labels);
171 else if (method ==
"update") {
177 else if (method ==
"predict") {
182 double confidence = 0;
183 obj->
predict(src, label, confidence);
190 else if (method ==
"predict_collect") {
191 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
193 for (
int i=3; i<nrhs; i+=2) {
194 string key(rhs[i].toString());
196 sorted = rhs[i+1].toBool();
199 "Unrecognized option %s", key.
c_str());
207 else if (method ==
"setLabelInfo") {
209 int label = rhs[2].toInt();
210 string strInfo(rhs[3].toString());
213 else if (method ==
"getLabelInfo") {
215 int label = rhs[2].toInt();
219 else if (method ==
"getLabelsByString") {
221 string str(rhs[2].toString());
225 else if (method ==
"getHistograms") {
229 else if (method ==
"getLabels") {
233 else if (method ==
"get") {
235 string prop(rhs[2].toString());
238 else if (prop ==
"GridY")
240 else if (prop ==
"Radius")
242 else if (prop ==
"Neighbors")
244 else if (prop ==
"Threshold")
248 "Unrecognized property %s", prop.
c_str());
250 else if (method ==
"set") {
252 string prop(rhs[2].toString());
255 else if (prop ==
"GridY")
257 else if (prop ==
"Radius")
259 else if (prop ==
"Neighbors")
261 else if (prop ==
"Threshold")
265 "Unrecognized property %s", prop.
c_str());
269 "Unrecognized operation %s", method.
c_str());
int toInt() const
Convert MxArray to int.
Ptr< LBPHFaceRecognizer > create_LBPHFaceRecognizer(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of LBPHFaceRecognizer using options in arguments.
virtual void setLabelInfo(int label, const String &strInfo)
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual std::vector< int > getLabelsByString(const String &str) const
virtual double getThreshold() const=0
virtual void setGridY(int val)=0
virtual int getGridY() const=0
virtual void update(InputArrayOfArrays src, InputArray labels)
virtual int getRadius() const=0
MxArray toStruct(const vector< pair< int, double > > &results)
Convert results to struct array.
virtual bool isOpened() const
virtual String getLabelInfo(int label) const
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
virtual void setGridX(int val)=0
virtual void read(const String &filename)
map< int, Ptr< LBPHFaceRecognizer > > obj_
Object container.
virtual String releaseAndGetString()
virtual void setRadius(int val)=0
virtual void write(const String &filename) 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...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
FileNode getFirstTopLevelNode() const
virtual std::vector< cv::Mat > getHistograms() const=0
int predict(InputArray src) const
virtual String getDefaultName() const
Global constant definitions.
virtual int getGridX() const=0
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual bool empty() const=0
std::vector< std::pair< int, double > > getResults(bool sorted=false) const
virtual void setNeighbors(int val)=0
virtual cv::Mat getLabels() const=0
virtual int getNeighbors() const=0
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
int last_id
Last object id to allocate.
virtual void setThreshold(double val)=0
virtual void train(InputArrayOfArrays src, InputArray labels)=0