19 map<int,Ptr<BOWImgDescriptorExtractor> > obj_;
29 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
35 vector<MxArray> rhs(prhs, prhs+nrhs);
36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
43 Ptr<DescriptorExtractor> extractor;
46 rhs[2].toString(), rhs.end(), rhs.end());
47 else if (rhs[2].isCell() && rhs[2].numel() >= 2) {
48 vector<MxArray> args(rhs[2].toVector<MxArray>());
50 args[0].toString(), args.begin() + 1, args.end());
53 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
55 Ptr<DescriptorMatcher> matcher;
58 rhs[3].toString(), rhs.end(), rhs.end());
59 else if (rhs[3].isCell() && rhs[3].numel() >= 2) {
60 vector<MxArray> args(rhs[3].toVector<MxArray>());
62 args[0].toString(), args.begin() + 1, args.end());
65 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
66 obj_[++last_id] = makePtr<BOWImgDescriptorExtractor>(
73 Ptr<BOWImgDescriptorExtractor> obj = obj_[id];
74 if (method ==
"delete") {
78 else if (method ==
"descriptorSize") {
80 plhs[0] =
MxArray(obj->descriptorSize());
82 else if (method ==
"descriptorType") {
86 else if (method ==
"compute") {
88 Mat image(rhs[2].toMat(CV_8U)),
89 imgDescriptor, descriptors;
90 vector<KeyPoint> keypoints(rhs[3].toVector<KeyPoint>());
91 vector<vector<int> > pointIdxsOfClusters;
92 obj->compute(image, keypoints, imgDescriptor,
93 (nlhs>1 ? &pointIdxsOfClusters : NULL),
94 (nlhs>2 ? &descriptors : NULL));
95 plhs[0] =
MxArray(imgDescriptor);
97 plhs[1] =
MxArray(pointIdxsOfClusters);
101 else if (method ==
"compute1") {
103 Mat keypointDescriptors(rhs[2].toMat(rhs[2].isUint8() ? CV_8U : CV_32F)),
105 vector<vector<int> > pointIdxsOfClusters;
106 obj->compute(keypointDescriptors, imgDescriptor,
107 (nlhs>1 ? &pointIdxsOfClusters : NULL));
108 plhs[0] =
MxArray(imgDescriptor);
110 plhs[1] =
MxArray(pointIdxsOfClusters);
112 else if (method ==
"compute2") {
114 Mat image(rhs[2].toMat(CV_8U)),
116 vector<KeyPoint> keypoints(rhs[3].toVector<KeyPoint>());
117 obj->compute2(image, keypoints, imgDescriptor);
118 plhs[0] =
MxArray(imgDescriptor);
120 else if (method ==
"get") {
122 string prop(rhs[2].toString());
123 if (prop ==
"Vocabulary")
124 plhs[0] =
MxArray(obj->getVocabulary());
126 mexErrMsgIdAndTxt(
"mexopencv:error",
127 "Unrecognized property %s", prop.c_str());
129 else if (method ==
"set") {
131 string prop(rhs[2].toString());
132 if (prop ==
"Vocabulary")
133 obj->setVocabulary(rhs[3].toMat(rhs[3].isUint8() ? CV_8U : CV_32F));
135 mexErrMsgIdAndTxt(
"mexopencv:error",
136 "Unrecognized property %s", prop.c_str());
139 mexErrMsgIdAndTxt(
"mexopencv:error",
140 "Unrecognized operation %s", method.c_str());
cv::Ptr< cv::DescriptorExtractor > createDescriptorExtractor(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Factory function for DescriptorExtractor creation.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Common definitions for the features2d and xfeatures2d modules.
cv::Ptr< cv::DescriptorMatcher > createDescriptorMatcher(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Factory function for DescriptorMatcher creation.
const ConstMap< int, std::string > ClassNameInvMap
Translates data type definition used in OpenCV to that of MATLAB.
Global constant definitions.