19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
25 vector<MxArray> rhs(prhs, prhs+nrhs);
26 string method(rhs[0].toString());
29 if (method ==
"removeDuplicated") {
31 vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
32 KeyPointsFilter::removeDuplicated(keypoints);
35 else if (method ==
"retainBest") {
37 vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
38 int npoints = rhs[2].toInt();
39 KeyPointsFilter::retainBest(keypoints, npoints);
42 else if (method ==
"runByImageBorder") {
44 vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
45 Size imageSize(rhs[2].toSize());
46 int borderSize = rhs[3].toInt();
47 KeyPointsFilter::runByImageBorder(keypoints, imageSize, borderSize);
50 else if (method ==
"runByKeypointSize") {
51 nargchk((nrhs==3 || nrhs==4) && nlhs<=1);
52 vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
53 float minSize = rhs[2].toFloat();
54 float maxSize = (nrhs==4) ? rhs[3].toFloat() : FLT_MAX;
55 KeyPointsFilter::runByKeypointSize(keypoints, minSize, maxSize);
58 else if (method ==
"runByPixelsMask") {
60 vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
61 Mat mask(rhs[2].toMat(CV_8U));
62 KeyPointsFilter::runByPixelsMask(keypoints, mask);
65 else if (method ==
"convertToPoints") {
66 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
67 vector<int> keypointIndexes;
68 for (
int i=2; i<nrhs; i+=2) {
69 string key(rhs[i].toString());
71 keypointIndexes = rhs[i+1].toVector<
int>();
73 mexErrMsgIdAndTxt(
"mexopencv:error",
74 "Unrecognized option %s", key.c_str());
76 vector<KeyPoint> keypoints(rhs[1].toVector<KeyPoint>());
77 vector<Point2f> points2f;
78 KeyPoint::convert(keypoints, points2f, keypointIndexes);
81 else if (method ==
"convertFromPoints") {
82 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
84 float response = 1.0f;
87 for (
int i=2; i<nrhs; i+=2) {
88 string key(rhs[i].toString());
90 size = rhs[i+1].toFloat();
91 else if (key ==
"Response")
92 response = rhs[i+1].toFloat();
93 else if (key ==
"Octave")
94 octave = rhs[i+1].toInt();
95 else if (key ==
"ClassId")
96 class_id = rhs[i+1].toInt();
98 mexErrMsgIdAndTxt(
"mexopencv:error",
99 "Unrecognized option %s", key.c_str());
101 vector<Point2f> points2f(rhs[1].toVector<Point2f>());
102 vector<KeyPoint> keypoints;
103 KeyPoint::convert(points2f, keypoints,
104 size, response, octave, class_id);
107 else if (method ==
"overlap") {
109 KeyPoint kp1 = rhs[1].toKeyPoint(),
110 kp2 = rhs[2].toKeyPoint();
111 float ovrl = KeyPoint::overlap(kp1, kp2);
114 else if (method ==
"hash") {
116 KeyPoint kp = rhs[1].toKeyPoint();
117 size_t val = kp.hash();
119 plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
121 uint64_t *data =
reinterpret_cast<uint64_t*
>(mxGetData(plhs[0]));
122 data[0] =
static_cast<uint64_t
>(val);
126 mexErrMsgIdAndTxt(
"mexopencv:error",
127 "Unrecognized operation %s", method.c_str());
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.