37 int num_components = 0;
39 for (; first != last; first += 2) {
40 string key(first->toString());
41 const MxArray& val = *(first + 1);
42 if (key ==
"NumComponents")
43 num_components = val.
toInt();
44 else if (key ==
"Threshold")
48 "Unrecognized option %s", key.c_str());
51 if (
type ==
"Eigenfaces")
53 else if (
type ==
"Fisherfaces")
57 "Unrecognized face recognizer %s",
type.c_str());
60 "Failed to create BasicFaceRecognizer");
70 const char *fields[] = {
"label",
"distance"};
72 for (
mwIndex i = 0; i < results.size(); ++i) {
73 s.
set(
"label", results[i].first, i);
74 s.
set(
"distance", results[i].second, i);
94 int id = rhs[0].toInt();
95 string method(rhs[1].toString());
98 if (method ==
"new") {
101 rhs[2].toString(), rhs.
begin() + 3, rhs.
end());
111 if (method ==
"delete") {
116 else if (method ==
"typeid") {
118 plhs[0] =
MxArray(
string(
typeid(*obj).name()));
120 else if (method ==
"clear") {
124 else if (method ==
"read") {
125 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
126 bool loadFromString =
false;
127 for (
int i=3; i<nrhs; i+=2) {
128 string key(rhs[i].toString());
129 if (key ==
"FromString")
130 loadFromString = rhs[i+1].toBool();
133 "Unrecognized option %s", key.
c_str());
135 string fname(rhs[2].toString());
136 if (loadFromString) {
137 FileStorage fs(fname, FileStorage::READ + FileStorage::MEMORY);
145 else if (method ==
"write") {
147 string fname(rhs[2].toString());
150 FileStorage fs(fname, FileStorage::WRITE + FileStorage::MEMORY);
162 else if (method ==
"empty") {
166 else if (method ==
"getDefaultName") {
170 else if (method ==
"train") {
181 obj->
train(src, labels);
183 else if (method ==
"update") {
196 else if (method ==
"predict") {
201 double confidence = 0;
202 obj->
predict(src, label, confidence);
209 else if (method ==
"predict_collect") {
210 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
212 for (
int i=3; i<nrhs; i+=2) {
213 string key(rhs[i].toString());
215 sorted = rhs[i+1].toBool();
218 "Unrecognized option %s", key.
c_str());
226 else if (method ==
"setLabelInfo") {
228 int label = rhs[2].toInt();
229 string strInfo(rhs[3].toString());
232 else if (method ==
"getLabelInfo") {
234 int label = rhs[2].toInt();
238 else if (method ==
"getLabelsByString") {
240 string str(rhs[2].toString());
244 else if (method ==
"getProjections") {
248 else if (method ==
"getLabels") {
252 else if (method ==
"getEigenValues") {
256 else if (method ==
"getEigenVectors") {
260 else if (method ==
"getMean") {
264 else if (method ==
"get") {
266 string prop(rhs[2].toString());
267 if (prop ==
"NumComponents")
269 else if (prop ==
"Threshold")
273 "Unrecognized property %s", prop.
c_str());
275 else if (method ==
"set") {
277 string prop(rhs[2].toString());
278 if (prop ==
"NumComponents")
280 else if (prop ==
"Threshold")
284 "Unrecognized property %s", prop.
c_str());
288 "Unrecognized operation %s", method.
c_str());
int toInt() const
Convert MxArray to int.
virtual void setLabelInfo(int label, const String &strInfo)
Ptr< BasicFaceRecognizer > create_BasicFaceRecognizer(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of BasicFaceRecognizer using options in arguments.
void setThreshold(double val)
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
std::vector< cv::Mat > getProjections() const
virtual void read(const FileNode &fn)
virtual void update(InputArrayOfArrays src, InputArray labels)
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.
int last_id
Last object id to allocate.
int getNumComponents() const
virtual String releaseAndGetString()
cv::Mat getEigenValues() 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 toStruct(const vector< pair< int, double > > &results)
Convert results to struct array.
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
cv::Mat getLabels() const
map< int, Ptr< BasicFaceRecognizer > > obj_
Object container.
void setNumComponents(int val)
virtual bool empty() const
int predict(InputArray src) const
virtual String getDefaultName() const
virtual void write(FileStorage &fs) const
Global constant definitions.
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
double getThreshold() const
std::vector< std::pair< int, double > > getResults(bool sorted=false) const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Mat getEigenVectors() const
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
virtual void train(InputArrayOfArrays src, InputArray labels)=0