Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit fd3eb0d

Browse files
committed
ADD: BFMatcher Bindings & Worker
ADD: match and matchAsync for BFMatcher
1 parent 903afa4 commit fd3eb0d

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

cc/modules/features2d/BFMatcher.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "BFMatcher.h"
2+
#include "BFMatcherBindings.h"
23

34
Nan::Persistent<v8::FunctionTemplate> BFMatcher::constructor;
45

@@ -49,4 +50,19 @@ NAN_METHOD(BFMatcher::New) {
4950
info.GetReturnValue().Set(info.Holder());
5051
}
5152

53+
NAN_METHOD(BFMatcher::match) {
54+
FF::SyncBinding(
55+
std::make_shared<BFMatcherBindings::MatchWorker>(FF_UNWRAP(info.This(), BFMatcher)->bfmatcher),
56+
"BFMatcher::match",
57+
info
58+
);
59+
}
60+
61+
NAN_METHOD(BFMatcher::matchAsync) {
62+
FF::AsyncBinding(
63+
std::make_shared<BFMatcherBindings::MatchWorker>(FF_UNWRAP(info.This(), BFMatcher)->bfmatcher),
64+
"FeatureDetector::matchAsync",
65+
info
66+
);
67+
}
5268

cc/modules/features2d/BFMatcher.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "macros.h"
2-
#include "NativeNodeUtils.h"
2+
#include <opencv2/core.hpp>
33
#include <opencv2/features2d.hpp>
4+
#include "KeyPoint.h"
5+
#include "Mat.h"
6+
#include "CatchCvExceptionWorker.h"
47

58
#ifndef __FF_BFMATCHER_H__
69
#define __FF_BFMATCHER_H__
@@ -25,11 +28,8 @@ class BFMatcher : public Nan::ObjectWrap {
2528
static NAN_MODULE_INIT(Init);
2629

2730
static NAN_METHOD(New);
28-
// static NAN_METHOD(Clone);
29-
// static NAN_METHOD(Create);
30-
// static NAN_METHOD(IsMaskSupported);
31-
// static NAN_METHOD(KnnMatchImpl);
32-
// static NAN_METHOD(RadiusMatchImpl);
31+
static NAN_METHOD(match);
32+
static NAN_METHOD(matchAsync);
3333

3434
static const char* getClassName() {
3535
return "BFMatcher";
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "BFMatcher.h"
2+
3+
#ifndef __FF_BFMATCHERBINDINGS_H_
4+
#define __FF_BFMATCHERBINDINGS_H_
5+
6+
namespace BFMatcherBindings {
7+
8+
struct MatchWorker : public CatchCvExceptionWorker {
9+
public:
10+
cv::Ptr<cv::BFMatcher> bfmatcher;
11+
MatchWorker(cv::Ptr<cv::BFMatcher> _bfmatcher) {
12+
this->bfmatcher = _bfmatcher;
13+
}
14+
15+
cv::Mat descFrom;
16+
cv::Mat descTo;
17+
std::vector<cv::DMatch> dmatches;
18+
19+
std::string executeCatchCvExceptionWorker() {
20+
bfmatcher->match(descFrom, descTo, dmatches);
21+
return "";
22+
}
23+
24+
bool unwrapRequiredArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
25+
return Mat::Converter::arg(0, &descFrom, info)
26+
|| Mat::Converter::arg(1, &descTo, info);
27+
}
28+
29+
FF_VAL getReturnValue() {
30+
return ObjectArrayConverter<BFMatcher, cv::DMatch>::wrap(dmatches);
31+
}
32+
};
33+
}
34+
35+
#endif

0 commit comments

Comments
 (0)