18 map<int,Ptr<HausdorffDistanceExtractor> > obj_;
28 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
34 vector<MxArray> rhs(prhs, prhs+nrhs);
35 int id = rhs[0].toInt();
36 string method(rhs[1].toString());
39 if (method ==
"new") {
42 rhs.begin() + 2, rhs.end());
48 Ptr<HausdorffDistanceExtractor> obj = obj_[id];
49 if (method ==
"delete") {
53 else if (method ==
"clear") {
57 else if (method ==
"load") {
58 nargchk(nrhs>=3 && (nrhs%2)!=0 && nlhs==0);
60 bool loadFromString =
false;
61 for (
int i=3; i<nrhs; i+=2) {
62 string key(rhs[i].toString());
64 objname = rhs[i+1].toString();
65 else if (key ==
"FromString")
66 loadFromString = rhs[i+1].toBool();
68 mexErrMsgIdAndTxt(
"mexopencv:error",
69 "Unrecognized option %s", key.c_str());
78 FileStorage fs(rhs[2].toString(), FileStorage::READ +
79 (loadFromString ? FileStorage::MEMORY : 0));
80 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
82 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
85 else if (method ==
"save") {
87 obj->save(rhs[2].toString());
89 else if (method ==
"empty") {
91 plhs[0] =
MxArray(obj->empty());
93 else if (method ==
"getDefaultName") {
95 plhs[0] =
MxArray(obj->getDefaultName());
97 else if (method ==
"computeDistance") {
100 if (rhs[2].isNumeric() && rhs[3].isNumeric()) {
102 Mat contour1(rhs[2].toMat(CV_32F).reshape(2,1)),
103 contour2(rhs[3].toMat(CV_32F).reshape(2,1));
104 dist = obj->computeDistance(contour1, contour2);
106 else if (rhs[2].isCell() && rhs[3].isCell()) {
107 vector<Point2f> contour1(rhs[2].toVector<Point2f>()),
108 contour2(rhs[3].toVector<Point2f>());
109 dist = obj->computeDistance(contour1, contour2);
112 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid argument");
115 else if (method ==
"get") {
117 string prop(rhs[2].toString());
118 if (prop ==
"DistanceFlag")
120 else if (prop ==
"RankProportion")
121 plhs[0] =
MxArray(obj->getRankProportion());
123 mexErrMsgIdAndTxt(
"mexopencv:error",
124 "Unrecognized property %s", prop.c_str());
126 else if (method ==
"set") {
128 string prop(rhs[2].toString());
129 if (prop ==
"DistanceFlag")
130 obj->setDistanceFlag(
NormType[rhs[3].toString()]);
131 else if (prop ==
"RankProportion")
132 obj->setRankProportion(rhs[3].toFloat());
134 mexErrMsgIdAndTxt(
"mexopencv:error",
135 "Unrecognized property %s", prop.c_str());
138 mexErrMsgIdAndTxt(
"mexopencv:error",
139 "Unrecognized operation %s", method.c_str());
Common definitions for the shape module.
const ConstMap< int, std::string > NormTypeInv
Inverse norm type map for option processing.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
cv::Ptr< cv::HausdorffDistanceExtractor > create_HausdorffDistanceExtractor(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of HausdorffDistanceExtractor using options in arguments.
const ConstMap< std::string, int > NormType
Norm type map for option processing.