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

Commit c94691c

Browse files
committed
ADD: match and matchAsync to BFMatcher
ADD: tests to BFMatcher in features2d
1 parent fd3eb0d commit c94691c

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

cc/modules/features2d/BFMatcher.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ NAN_MODULE_INIT(BFMatcher::Init) {
1111
instanceTemplate->SetInternalFieldCount(1);
1212

1313
ctor->SetClassName(Nan::New("BFMatcher").ToLocalChecked());
14-
// ctor->SetClassName(FF_NEW_STRING("BFMatcher"));
15-
1614

1715
Nan::SetAccessor(instanceTemplate, Nan::New("normType").ToLocalChecked(), BFMatcher::GetNormType);
1816
Nan::SetAccessor(instanceTemplate, Nan::New("crossCheck").ToLocalChecked(), BFMatcher::GetCrossCheck);
1917

20-
// Nan::SetPrototypeMethod(ctor, "create", create);
21-
18+
Nan::SetPrototypeMethod(ctor, "match", match);
19+
Nan::SetPrototypeMethod(ctor, "matchAsync", matchAsync);
2220

2321
target->Set(Nan::New("BFMatcher").ToLocalChecked(), ctor->GetFunction());
24-
// target->Set(FF_NEW_STRING("BFMatcher"), ctor->GetFunction());
25-
2622
};
2723

2824
NAN_METHOD(BFMatcher::New) {
@@ -52,17 +48,17 @@ NAN_METHOD(BFMatcher::New) {
5248

5349
NAN_METHOD(BFMatcher::match) {
5450
FF::SyncBinding(
55-
std::make_shared<BFMatcherBindings::MatchWorker>(FF_UNWRAP(info.This(), BFMatcher)->bfmatcher),
51+
std::make_shared<BFMatcherBindings::MatchWorker>(BFMatcher::Converter::unwrap(info.This())),
5652
"BFMatcher::match",
5753
info
5854
);
5955
}
6056

6157
NAN_METHOD(BFMatcher::matchAsync) {
6258
FF::AsyncBinding(
63-
std::make_shared<BFMatcherBindings::MatchWorker>(FF_UNWRAP(info.This(), BFMatcher)->bfmatcher),
64-
"FeatureDetector::matchAsync",
65-
info
59+
std::make_shared<BFMatcherBindings::MatchWorker>(BFMatcher::Converter::unwrap(info.This())),
60+
"FeatureDetector::matchAsync",
61+
info
6662
);
6763
}
6864

cc/modules/features2d/BFMatcherBindings.h

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

34
#ifndef __FF_BFMATCHERBINDINGS_H_
45
#define __FF_BFMATCHERBINDINGS_H_
@@ -7,8 +8,9 @@ namespace BFMatcherBindings {
78

89
struct MatchWorker : public CatchCvExceptionWorker {
910
public:
10-
cv::Ptr<cv::BFMatcher> bfmatcher;
11-
MatchWorker(cv::Ptr<cv::BFMatcher> _bfmatcher) {
11+
cv::BFMatcher bfmatcher;
12+
13+
MatchWorker(cv::BFMatcher _bfmatcher) {
1214
this->bfmatcher = _bfmatcher;
1315
}
1416

@@ -17,7 +19,7 @@ struct MatchWorker : public CatchCvExceptionWorker {
1719
std::vector<cv::DMatch> dmatches;
1820

1921
std::string executeCatchCvExceptionWorker() {
20-
bfmatcher->match(descFrom, descTo, dmatches);
22+
bfmatcher.match(descFrom, descTo, dmatches);
2123
return "";
2224
}
2325

@@ -27,7 +29,7 @@ struct MatchWorker : public CatchCvExceptionWorker {
2729
}
2830

2931
FF_VAL getReturnValue() {
30-
return ObjectArrayConverter<BFMatcher, cv::DMatch>::wrap(dmatches);
32+
return ObjectArrayConverter<DescriptorMatch, cv::DMatch>::wrap(dmatches);
3133
}
3234
};
3335
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const cv = global.dut;
2+
const { assertPropsWithValue, generateAPITests } = global.utils;
3+
4+
const { expect } = require('chai');
5+
6+
module.exports = (getTestImg) => {
7+
describe('BFMatcher', () => {
8+
describe('constructor', () => {
9+
const normType = cv.NORM_L2;
10+
const crossCheck = true;
11+
12+
it('should throw if insufficient args passed', () => {
13+
expect(() => new cv.BFMatcher(undefined)).to.throw();
14+
});
15+
16+
it('should throw if bag args are passed', () => {
17+
expect(() => new cv.BFMatcher(normType, undefined)).to.throw();
18+
});
19+
20+
it('should be constructable with required args', () => {
21+
expect(() => new cv.BFMatcher(normType)).to.not.throw();
22+
});
23+
24+
it('should initialize with correct values', () => {
25+
const match = new cv.BFMatcher(normType, crossCheck);
26+
assertPropsWithValue(match)({ normType, crossCheck });
27+
});
28+
});
29+
30+
describe('match', () => {
31+
let BFMatcher;
32+
33+
before(() => {
34+
BFMatcher = new cv.BFMatcher(cv.NORM_L2, true);
35+
36+
const kaze = new cv.KAZEDetector();
37+
kazeKps = kaze.detect(getTestImg());
38+
kazeDesc = kaze.compute(getTestImg(), kazeKps);
39+
});
40+
41+
describe('matchBruteForce', () => {
42+
it('sync', () => {
43+
const matches = BFMatcher.match(kazeDesc, kazeDesc);
44+
expect(kazeKps.length).to.be.above(0);
45+
expect(matches).to.be.an('array').lengthOf(kazeKps.length);
46+
matches.forEach(match => expect(match).instanceOf(cv.DescriptorMatch));
47+
});
48+
49+
it('async', (done) => {
50+
cv.matchBruteForceAsync(kazeDesc, kazeDesc, (err, matches) => {
51+
expect(kazeKps.length).to.be.above(0);
52+
expect(matches).to.be.an('array').lengthOf(kazeKps.length);
53+
matches.forEach(match => expect(match).instanceOf(cv.DescriptorMatch));
54+
done();
55+
});
56+
});
57+
});
58+
});
59+
});
60+
};

test/tests/modules/features2d/features2d.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const detectorTests = require('./detectorTests');
55
const KeyPointTests = require('./KeyPointTests');
66
const DescriptorMatchTests = require('./DescriptorMatchTests');
77
const descriptorMatchingTests = require('./descriptorMatchingTests');
8+
const BFMatcherTests = require('./BFMatcherTests');
89

910
describe('features2d', () => {
1011
let testImg;
@@ -15,6 +16,7 @@ describe('features2d', () => {
1516
KeyPointTests();
1617
DescriptorMatchTests();
1718
descriptorMatchingTests(() => testImg);
19+
BFMatcherTests(() => testImg);
1820

1921
describe('AGASTDetector', () => {
2022
const defaults = {

0 commit comments

Comments
 (0)