36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
41 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
44 for (
int i=2; i<nrhs; i+=2) {
45 string key(rhs[i].toString());
47 ctr = rhs[i+1].toInt();
48 else if (key ==
"FDSize")
49 fd = rhs[i+1].toInt();
52 "Unrecognized option %s", key.
c_str());
60 else if (method ==
"contourSampling") {
62 int nbElt = rhs[3].toInt();
63 if (rhs[2].isCell()) {
70 bool cn1 = (src.channels() == 1);
71 if (cn1) src = src.
reshape(2,0);
73 if (cn1) out = out.
reshape(1,0);
78 else if (method ==
"fourierDescriptor") {
79 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
82 for (
int i=3; i<nrhs; i+=2) {
83 string key(rhs[i].toString());
85 nbElt = rhs[i+1].toInt();
86 else if (key ==
"NumFD")
87 nbFD = rhs[i+1].toInt();
90 "Unrecognized option %s", key.
c_str());
93 if (rhs[2].isCell()) {
104 else if (method ==
"transformFD") {
105 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=1);
106 bool fdContour =
true;
107 for (
int i=4; i<nrhs; i+=2) {
108 string key(rhs[i].toString());
110 fdContour = rhs[i+1].toBool();
113 "Unrecognized option %s", key.
c_str());
123 bool cn1 = (src.channels() == 1);
124 if (cn1) src = src.
reshape(2,0);
126 if (cn1) dst = dst.
reshape(1,0);
136 if (method ==
"delete") {
141 else if (method ==
"clear") {
145 else if (method ==
"load") {
146 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
148 bool loadFromString =
false;
149 for (
int i=3; i<nrhs; i+=2) {
150 string key(rhs[i].toString());
151 if (key ==
"ObjName")
152 objname = rhs[i+1].toString();
153 else if (key ==
"FromString")
154 loadFromString = rhs[i+1].toBool();
157 "Unrecognized option %s", key.
c_str());
166 FileStorage fs(rhs[2].toString(), FileStorage::READ +
167 (loadFromString ? FileStorage::MEMORY : 0));
176 else if (method ==
"save") {
178 obj->
save(rhs[2].toString());
180 else if (method ==
"empty") {
184 else if (method ==
"getDefaultName") {
188 else if (method ==
"estimateTransformation") {
189 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
190 bool fdContour =
false;
191 for (
int i=4; i<nrhs; i+=2) {
192 string key(rhs[i].toString());
194 fdContour = rhs[i+1].toBool();
197 "Unrecognized option %s", key.
c_str());
203 ref(rhs[3].toVector<Point2f>());
215 else if (method ==
"get") {
217 string prop(rhs[2].toString());
218 if (prop ==
"CtrSize")
220 else if (prop ==
"FDSize")
224 "Unrecognized property %s", prop.
c_str());
226 else if (method ==
"set") {
228 string prop(rhs[2].toString());
229 if (prop ==
"CtrSize")
231 else if (prop ==
"FDSize")
235 "Unrecognized property %s", prop.
c_str());
239 "Unrecognized operation %s", method.
c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void transformFD(InputArray src, InputArray t, OutputArray dst, bool fdContour=true)
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
int last_id
Last object id to allocate.
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
map< int, Ptr< ContourFitting > > obj_
Object container.
virtual void read(const FileNode &fn)
Mat reshape(int cn, int rows=0) 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.
void contourSampling(InputArray src, OutputArray out, int nbElt)
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
FileNode getFirstTopLevelNode() const
virtual String getDefaultName() const
Global constant definitions.
void fourierDescriptor(InputArray src, OutputArray dst, int nbElt=-1, int nbFD=-1)
virtual void save(const String &filename) const
virtual bool empty() const
void estimateTransformation(InputArray src, InputArray dst, OutputArray alphaPhiST, double *dist=0, bool fdContour=false)
Ptr< ContourFitting > createContourFitting(int ctr=1024, int fd=16)