15 static const int nTrees = 5;
36 const char *fields[] = {
"first",
"second"};
38 for (
mwIndex i = 0; i < correspondences.size(); ++i) {
39 s.
set(
"first", correspondences[i].first, i);
40 s.
set(
"second", correspondences[i].second, i);
60 int id = rhs[0].toInt();
61 string method(rhs[1].toString());
64 if (method ==
"new") {
76 if (method ==
"delete") {
81 else if (method ==
"clear") {
85 else if (method ==
"load") {
86 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
88 bool loadFromString =
false;
89 for (
int i=3; i<nrhs; i+=2) {
90 string key(rhs[i].toString());
92 objname = rhs[i+1].toString();
93 else if (key ==
"FromString")
94 loadFromString = rhs[i+1].toBool();
97 "Unrecognized option %s", key.
c_str());
99 obj_[id] = (loadFromString ?
100 Algorithm::loadFromString<GPCForest5>(rhs[2].toString(), objname) :
101 Algorithm::load<GPCForest5>(rhs[2].toString(), objname));
103 else if (method ==
"save") {
105 obj->
save(rhs[2].toString());
107 else if (method ==
"empty") {
111 else if (method ==
"getDefaultName") {
115 else if (method ==
"train") {
116 nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs==0);
117 unsigned maxTreeDepth = 20;
118 int minNumberOfSamples = 3;
120 bool printProgress =
false;
121 for (
int i=5; i<nrhs; i+=2) {
122 string key(rhs[i].toString());
123 if (key ==
"MaxTreeDepth")
124 maxTreeDepth =
static_cast<unsigned>(rhs[i+1].toInt());
125 else if (key ==
"MinNumberOfSamples")
126 minNumberOfSamples = rhs[i+1].toInt();
127 else if (key ==
"DescriptorType")
129 else if (key ==
"PrintProgress")
130 printProgress = rhs[i+1].toBool();
133 "Unrecognized option %s", key.
c_str());
136 maxTreeDepth, minNumberOfSamples, descriptorType, printProgress);
137 if (!rhs[2].isCell() || !rhs[3].isCell() || !rhs[4].isCell())
139 if (!rhs[2].isEmpty() && rhs[2].at<MxArray>(0).isChar()) {
141 imagesTo(rhs[3].toVector<string>()),
142 gt(rhs[4].toVector<string>());
151 imagesTo(rhs[3].toVector<Mat>()),
152 gt(rhs[4].toVector<Mat>());
153 obj->
train(imagesFrom, imagesTo, gt, params);
156 else if (method ==
"findCorrespondences") {
157 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=1);
159 for (
int i=4; i<nrhs; i+=2) {
160 string key(rhs[i].toString());
161 if (key ==
"UseOpenCL")
165 "Unrecognized option %s", key.
c_str());
169 imgTo(rhs[3].
toMat());
176 "Unrecognized operation %s", method.
c_str());
int last_id
Last object id to allocate.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void train(GPCTrainingSamples &samples, const GPCTrainingParams params=GPCTrainingParams())
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
void findCorrespondences(InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, const GPCMatchingParams params=GPCMatchingParams()) const
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
cv::optflow::GPCForest< nTrees > GPCForest5
map< int, Ptr< GPCForest5 > > obj_
Object container.
static Ptr< GPCForest > create()
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.
MxArray toStruct(const vector< pair< Point2i, Point2i > > &correspondences)
Convert correspondences to struct array.
const ConstMap< string, GPCDescType > GPCDescTypeMap
GPC descriptor types for option processing.
virtual String getDefaultName() const
Global constant definitions.
virtual void save(const String &filename) const
virtual bool empty() const
std::map wrapper with one-line initialization and lookup method.