Skip to content

Commit cb86367

Browse files
opatinytargos
authored andcommitted
test: enhance drawMatches tests
1 parent 3ecd53a commit cb86367

6 files changed

+52
-18
lines changed

src/featureMatching/__tests__/bruteForceMatch.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { ImageColorModel } from '../../Image';
1+
import { ImageColorModel, Image } from '../../Image';
22
import { bruteForceOneMatch } from '../bruteForceMatch';
3-
import { getBriefDescriptors } from '../getBriefDescriptors';
3+
import { BriefDescriptor, getBriefDescriptors } from '../getBriefDescriptors';
44
import { getOrientedFastKeypoints } from '../getOrientedFastKeypoints';
55

6-
const source = testUtils.load('various/alphabet.jpg');
7-
const grey = source.convertColor(ImageColorModel.GREY);
8-
const sourceKeypoints = getOrientedFastKeypoints(grey);
9-
const sourceDescriptors = getBriefDescriptors(grey, sourceKeypoints);
10-
11-
const destination = testUtils.load('various/alphabet.jpg');
12-
const grey2 = destination.convertColor(ImageColorModel.GREY);
13-
const destinationKeypoints = getOrientedFastKeypoints(grey2);
14-
const destinationDescriptors = getBriefDescriptors(grey2, destinationKeypoints);
6+
function getDescriptors(image: Image): BriefDescriptor[] {
7+
const grey = image.convertColor(ImageColorModel.GREY);
8+
const sourceKeypoints = getOrientedFastKeypoints(grey);
9+
return getBriefDescriptors(grey, sourceKeypoints);
10+
}
1511

1612
test('nbBestMatches = 5', () => {
13+
const source = testUtils.load('featureMatching/alphabet.jpg');
14+
const sourceDescriptors = getDescriptors(source);
15+
const destination = testUtils.load('featureMatching/alphabet.jpg');
16+
const destinationDescriptors = getDescriptors(destination);
17+
1718
const matches = bruteForceOneMatch(
1819
sourceDescriptors,
1920
destinationDescriptors,

src/featureMatching/__tests__/drawMatches.test.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { drawMatches } from '../drawMatches';
44
import { getBriefDescriptors } from '../getBriefDescriptors';
55
import { getOrientedFastKeypoints } from '../getOrientedFastKeypoints';
66

7-
test('alphabet image as source and destination', () => {
7+
test('alphabet image as source and destination, nbKeypoint = 10', () => {
88
const source = testUtils.load('various/alphabet.jpg');
99
const grey = source.convertColor(ImageColorModel.GREY);
1010
const sourceKeypoints = getOrientedFastKeypoints(grey, { maxNbFeatures: 10 });
@@ -33,17 +33,50 @@ test('alphabet image as source and destination', () => {
3333
expect(result).toMatchImageSnapshot();
3434
});
3535

36-
test('destination rotated', () => {
37-
const source = testUtils.load('various/alphabet.jpg');
36+
test('destination rotated +2°', () => {
37+
const source = testUtils
38+
.load('featureMatching/alphabet.jpg')
39+
.convertColor(ImageColorModel.GREY);
40+
const sourceKeypoints = getOrientedFastKeypoints(source);
41+
const sourceDescriptors = getBriefDescriptors(source, sourceKeypoints);
42+
43+
const destination = testUtils
44+
.load('featureMatching/alphabetRotated2.jpg')
45+
.convertColor(ImageColorModel.GREY);
46+
const destinationKeypoints = getOrientedFastKeypoints(destination);
47+
const destinationDescriptors = getBriefDescriptors(
48+
destination,
49+
destinationKeypoints,
50+
);
51+
expect(sourceKeypoints.length).toBe(119);
52+
expect(destinationKeypoints.length).toBe(135);
53+
54+
const matches = bruteForceOneMatch(
55+
sourceDescriptors,
56+
destinationDescriptors,
57+
{ nbBestMatches: 20 },
58+
);
59+
60+
const result = drawMatches(
61+
source,
62+
destination,
63+
sourceKeypoints,
64+
destinationKeypoints,
65+
matches,
66+
{ showScore: true },
67+
);
68+
69+
expect(result).toMatchImageSnapshot();
70+
});
71+
72+
test('destination rotated +10°', () => {
73+
const source = testUtils.load('featureMatching/alphabet.jpg');
3874
const grey = source.convertColor(ImageColorModel.GREY);
3975
const sourceKeypoints = getOrientedFastKeypoints(grey);
4076
const sourceDescriptors = getBriefDescriptors(grey, sourceKeypoints);
4177

42-
const destination = testUtils
43-
.load('various/alphabet.jpg')
44-
.rotate(10, { fullImage: true });
78+
const destination = testUtils.load('featureMatching/alphabetRotated10.jpg');
4579
const grey2 = destination.convertColor(ImageColorModel.GREY);
46-
4780
const destinationKeypoints = getOrientedFastKeypoints(grey2);
4881
const destinationDescriptors = getBriefDescriptors(
4982
grey2,

0 commit comments

Comments
 (0)