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

Commit a938fdf

Browse files
committed
test(getOrientedFastKeypoints): enhance tests
1 parent 678363d commit a938fdf

7 files changed

+78
-25
lines changed
Loading
Loading
Loading
Loading

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

Lines changed: 78 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,6 @@ test('patch with one keypoint, centroidPatchDiameter=15', () => {
173173
]);
174174
});
175175

176-
test('check we handle edge cases properly', () => {
177-
const image = testUtils
178-
.load('featureMatching/crop1.png')
179-
.convertColor(ImageColorModel.GREY);
180-
181-
const keypoints = getOrientedFastKeypoints(image);
182-
183-
expect(keypoints.length).toBe(403);
184-
});
185-
186-
test('angle should never be NaN', () => {
187-
const image = testUtils
188-
.load('featureMatching/crop1.png')
189-
.convertColor(ImageColorModel.GREY);
190-
191-
const keypoints = getOrientedFastKeypoints(image);
192-
for (let keypoint of keypoints) {
193-
expect(isNaN(keypoint.angle)).toBe(false);
194-
}
195-
});
196-
197176
test.each([
198177
{
199178
message: 'betterScaleneTriangle',
@@ -203,20 +182,94 @@ test.each([
203182
message: 'betterScaleneTriangle90',
204183
image: 'betterScaleneTriangle90',
205184
},
206-
])('orientation should look correct ($message)', (data) => {
207-
const markerSize = 7;
185+
])('patchDiameter = 31 ($message)', (data) => {
186+
const centroidPatchDiameter = 31;
208187

209188
const image = testUtils
210189
.load(`featureMatching/polygons/${data.image}.png` as TestImagePath)
211190
.convertColor(ImageColorModel.GREY)
212191
.invert();
213-
const keypoints = getOrientedFastKeypoints(image);
192+
193+
const keypoints = getOrientedFastKeypoints(image, { centroidPatchDiameter });
214194

215195
expect(
216-
drawKeypoints(image, keypoints, { markerSize, showOrientation: true }),
196+
drawKeypoints(image, keypoints, {
197+
markerSize: centroidPatchDiameter,
198+
showOrientation: true,
199+
}),
217200
).toMatchImageSnapshot();
218201
});
219202

203+
test('verify single keypoint orientation', () => {
204+
const origin = { row: 332, column: 253 };
205+
const size = 51;
206+
const radius = (size - 1) / 2;
207+
208+
const cropOrigin = {
209+
row: origin.row - radius,
210+
column: origin.column - radius,
211+
};
212+
213+
const centroidPatchDiameter = 31;
214+
215+
const origialImage = testUtils
216+
.load('featureMatching/polygons/betterScaleneTriangle.png')
217+
.convertColor(ImageColorModel.GREY)
218+
.invert();
219+
220+
const image = origialImage.crop({
221+
origin: cropOrigin,
222+
width: size,
223+
height: size,
224+
});
225+
226+
const keypoints = getOrientedFastKeypoints(image, { centroidPatchDiameter });
227+
expect(keypoints.length).toBe(1);
228+
229+
const result = drawKeypoints(image, keypoints, {
230+
markerSize: centroidPatchDiameter,
231+
showOrientation: true,
232+
});
233+
234+
expect(result).toMatchImageSnapshot();
235+
});
236+
237+
test('small patchsize and large marker', () => {
238+
// this test shows that the orientation is not good when the centroidPatchDiameter is too small
239+
// ideally we should use the same patch size for orientation and descriptors (getKeypointPatch)
240+
const origin = { row: 730, column: 291 };
241+
const size = 51;
242+
const radius = (size - 1) / 2;
243+
244+
const cropOrigin = {
245+
row: origin.row - radius,
246+
column: origin.column - radius,
247+
};
248+
249+
const centroidPatchDiameter = 7;
250+
251+
const origialImage = testUtils
252+
.load('featureMatching/polygons/betterScaleneTriangle90.png')
253+
.convertColor(ImageColorModel.GREY)
254+
.invert();
255+
256+
const image = origialImage.crop({
257+
origin: cropOrigin,
258+
width: size,
259+
height: size,
260+
});
261+
262+
const keypoints = getOrientedFastKeypoints(image, { centroidPatchDiameter });
263+
expect(keypoints.length).toBe(1);
264+
265+
const result = drawKeypoints(image, keypoints, {
266+
markerSize: 31,
267+
showOrientation: true,
268+
});
269+
270+
expect(result).toMatchImageSnapshot();
271+
});
272+
220273
test('check angle for different windowSize', () => {
221274
const image = testUtils
222275
.load('featureMatching/polygons/scaleneTriangle10.png')

0 commit comments

Comments
 (0)