Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit d1d6ea0

Browse files
committed
test: add more simple matching tests
1 parent b708731 commit d1d6ea0

File tree

26 files changed

+198
-15
lines changed

26 files changed

+198
-15
lines changed

src/featureMatching/descriptors/__tests__/getBriefDescriptors.test.ts

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,51 @@ test('verify descriptor is correct (descriptorLength = 10)', () => {
113113
);
114114
});
115115

116-
test.only('compare scalene triangle keypoints', () => {
116+
test.each([
117+
{
118+
message: 'windowSize = 7',
119+
windowSize: 7,
120+
expected: [
121+
{ srcIndex: 0, dstIndex: 0, distance: 15 },
122+
{ srcIndex: 0, dstIndex: 1, distance: 73 },
123+
{ srcIndex: 1, dstIndex: 0, distance: 77 },
124+
{ srcIndex: 1, dstIndex: 1, distance: 11 },
125+
],
126+
},
127+
{
128+
message: 'windowSize = 15',
129+
windowSize: 15,
130+
expected: [
131+
{ srcIndex: 0, dstIndex: 0, distance: 13 },
132+
{ srcIndex: 0, dstIndex: 1, distance: 11 },
133+
{ srcIndex: 1, dstIndex: 0, distance: 23 },
134+
{ srcIndex: 1, dstIndex: 1, distance: 7 },
135+
],
136+
},
137+
{
138+
message: 'windowSize = 31',
139+
windowSize: 31,
140+
expected: [
141+
{ srcIndex: 0, dstIndex: 0, distance: 11 },
142+
{ srcIndex: 0, dstIndex: 1, distance: 14 },
143+
{ srcIndex: 1, dstIndex: 0, distance: 20 },
144+
{ srcIndex: 1, dstIndex: 1, distance: 9 },
145+
],
146+
},
147+
])('check distance for each keypoint pair ($message)', (data) => {
117148
const source = testUtils
118149
.load('featureMatching/polygons/scaleneTriangle.png')
119150
.convertColor(ImageColorModel.GREY);
120-
const sourceKeypoints = getOrientedFastKeypoints(source);
151+
const sourceKeypoints = getOrientedFastKeypoints(source, {
152+
windowSize: data.windowSize,
153+
});
121154
const sourceBrief = getBriefDescriptors(source, sourceKeypoints);
122155
const destination = testUtils
123156
.load('featureMatching/polygons/scaleneTriangle10.png')
124157
.convertColor(ImageColorModel.GREY);
125-
const destinationKeypoints = getOrientedFastKeypoints(destination);
158+
const destinationKeypoints = getOrientedFastKeypoints(destination, {
159+
windowSize: data.windowSize,
160+
});
126161
const destinationBrief = getBriefDescriptors(
127162
destination,
128163
destinationKeypoints,
@@ -147,11 +182,6 @@ test.only('compare scalene triangle keypoints', () => {
147182
}
148183
}
149184

150-
// 0-0 and 1-1 are the correct matches, so this looks good
151-
expect(result).toStrictEqual([
152-
{ srcIndex: 0, dstIndex: 0, distance: 15 },
153-
{ srcIndex: 0, dstIndex: 1, distance: 73 },
154-
{ srcIndex: 1, dstIndex: 0, distance: 77 },
155-
{ srcIndex: 1, dstIndex: 1, distance: 11 },
156-
]);
185+
// 0-0 and 1-1 are the correct matches
186+
expect(result).toStrictEqual(data.expected);
157187
});
Loading
Loading
Loading
Loading

src/featureMatching/descriptors/utils/__tests__/getKeypointPatch.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ test('patch had black pixels on border', () => {
5858

5959
expect(result).toMatchImageSnapshot();
6060
});
61+
62+
test.each([
63+
{
64+
message: 'scalene triangle',
65+
image: 'scaleneTriangle',
66+
},
67+
{
68+
message: 'scalene triangle rotated 10°',
69+
image: 'scaleneTriangle10',
70+
},
71+
])('windowSize = 15 ($message)', (data) => {
72+
const image = testUtils
73+
.load(`featureMatching/polygons/${data.image}.png` as TestImagePath)
74+
.convertColor(ImageColorModel.GREY);
75+
76+
const keypoints = getOrientedFastKeypoints(image, { windowSize: 15 });
77+
78+
for (let keypoint of keypoints) {
79+
expect(getKeypointPatch(image, keypoint)).toMatchImageSnapshot();
80+
}
81+
});

src/featureMatching/keypoints/__tests__/getOrientedFastKeypoints.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,55 @@ test('angle should never be NaN', () => {
9696
expect(isNaN(keypoint.angle)).toBe(false);
9797
}
9898
});
99+
100+
test('check angle for different windowSize', () => {
101+
const image = testUtils
102+
.load('featureMatching/polygons/scaleneTriangle10.png')
103+
.convertColor(ImageColorModel.GREY);
104+
105+
const keypoints7 = getOrientedFastKeypoints(image);
106+
const keypoints15 = getOrientedFastKeypoints(image, { windowSize: 15 });
107+
const keypoints31 = getOrientedFastKeypoints(image, { windowSize: 31 });
108+
109+
expect([keypoints7, keypoints15, keypoints31]).toBeDeepCloseTo(
110+
[
111+
[
112+
{
113+
origin: { row: 607, column: 132 },
114+
score: 2680,
115+
angle: 145.3,
116+
},
117+
{
118+
origin: { row: 50, column: 292 },
119+
score: 2662,
120+
angle: -112.2,
121+
},
122+
],
123+
[
124+
{
125+
origin: { row: 607, column: 132 },
126+
score: 2680,
127+
angle: 123.7,
128+
},
129+
{
130+
origin: { row: 50, column: 292 },
131+
score: 2662,
132+
angle: -95.4,
133+
},
134+
],
135+
[
136+
{
137+
origin: { row: 607, column: 132 },
138+
score: 2680,
139+
angle: 120,
140+
},
141+
{
142+
origin: { row: 50, column: 292 },
143+
score: 2662,
144+
angle: -92.1,
145+
},
146+
],
147+
],
148+
1,
149+
);
150+
});

src/featureMatching/keypoints/getOrientedFastKeypoints.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ export function getOrientedFastKeypoints(
4646

4747
const fastKeypoints = getFastKeypoints(image, options);
4848

49-
const borderDistance = getRadius(windowSize);
49+
const radius = getRadius(windowSize);
5050

5151
// handle edge cases: remove keypoints too close to border
5252
let keypoints: FastKeypoint[] = [];
5353
for (let keypoint of fastKeypoints) {
54-
if (checkBorderDistance(image, keypoint.origin, borderDistance)) {
54+
if (checkBorderDistance(image, keypoint.origin, radius)) {
5555
keypoints.push(keypoint);
5656
}
5757
}
@@ -60,7 +60,7 @@ export function getOrientedFastKeypoints(
6060
for (let keypoint of keypoints) {
6161
const centroid = getPatchIntensityCentroid(image, {
6262
origin: keypoint.origin,
63-
radius: borderDistance,
63+
radius,
6464
})[0];
6565
const angle = toDegrees(getAngle({ column: 0, row: 0 }, centroid));
6666
orientedFastKeypoints.push({ ...keypoint, angle });
Loading
46.1 KB
Loading

0 commit comments

Comments
 (0)