|
1 | 1 | import { ImageColorModel, Image, ImageCoordinates } from '../../../Image';
|
2 | 2 | import { getOrientedFastKeypoints } from '../../keypoints/getOrientedFastKeypoints';
|
3 |
| -import { getHammingDistance } from '../../matching/getHammingDistance'; |
4 |
| -import { drawKeypoints } from '../../visualize/drawKeypoints'; |
5 | 3 | import { getBriefDescriptors } from '../getBriefDescriptors';
|
6 | 4 |
|
7 |
| -test('alphabet image, maxNbFeatures = 10', () => { |
8 |
| - const image = testUtils.load('various/alphabet.jpg'); |
9 |
| - const grey = image.convertColor(ImageColorModel.GREY); |
10 |
| - |
11 |
| - const keypoints = getOrientedFastKeypoints(grey, { maxNbFeatures: 10 }); |
12 |
| - expect(keypoints).toHaveLength(10); |
13 |
| - |
14 |
| - let imageWithKeypoints = drawKeypoints(image, keypoints); |
15 |
| - |
16 |
| - expect(imageWithKeypoints).toMatchImageSnapshot(); |
17 |
| - |
18 |
| - const result = getBriefDescriptors(grey, keypoints); |
19 |
| - |
20 |
| - expect(result.descriptors).toMatchSnapshot(); |
21 |
| - expect(result.descriptors.length).toBe(keypoints.length); |
22 |
| -}); |
23 |
| - |
24 |
| -test('should work with small patch size', () => { |
25 |
| - const image = testUtils.load('various/alphabet.jpg'); |
26 |
| - const grey = image.convertColor(ImageColorModel.GREY); |
27 |
| - |
28 |
| - const keypoints = getOrientedFastKeypoints(grey, { maxNbFeatures: 10 }); |
29 |
| - expect(keypoints).toHaveLength(10); |
30 |
| - |
31 |
| - const keypoint = keypoints.slice(0, 1); |
32 |
| - |
33 |
| - let imageWithKeypoints = drawKeypoints(image, keypoints); |
34 |
| - expect(imageWithKeypoints).toMatchImageSnapshot(); |
35 |
| - |
36 |
| - const descriptor = getBriefDescriptors(grey, keypoint, { |
37 |
| - patchSize: 5, |
38 |
| - }).descriptors; |
39 |
| - |
40 |
| - expect(descriptor).toMatchSnapshot(); |
41 |
| -}); |
42 |
| - |
43 | 5 | test('count occurences of 1 and 0 with default options', () => {
|
44 | 6 | const image = testUtils.load('various/alphabet.jpg');
|
45 | 7 | const grey = image.convertColor(ImageColorModel.GREY);
|
@@ -112,76 +74,3 @@ test('verify descriptor is correct (descriptorLength = 10)', () => {
|
112 | 74 | new Uint8Array([0, 0, 0, 0, 0, 0, 1, 0, 1, 0]),
|
113 | 75 | );
|
114 | 76 | });
|
115 |
| - |
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) => { |
148 |
| - const source = testUtils |
149 |
| - .load('featureMatching/polygons/scaleneTriangle.png') |
150 |
| - .convertColor(ImageColorModel.GREY); |
151 |
| - const sourceKeypoints = getOrientedFastKeypoints(source, { |
152 |
| - windowSize: data.windowSize, |
153 |
| - }); |
154 |
| - const sourceBrief = getBriefDescriptors(source, sourceKeypoints); |
155 |
| - const destination = testUtils |
156 |
| - .load('featureMatching/polygons/scaleneTriangle10.png') |
157 |
| - .convertColor(ImageColorModel.GREY); |
158 |
| - const destinationKeypoints = getOrientedFastKeypoints(destination, { |
159 |
| - windowSize: data.windowSize, |
160 |
| - }); |
161 |
| - const destinationBrief = getBriefDescriptors( |
162 |
| - destination, |
163 |
| - destinationKeypoints, |
164 |
| - ); |
165 |
| - let result = []; |
166 |
| - |
167 |
| - for ( |
168 |
| - let srcIndex = 0; |
169 |
| - srcIndex < sourceBrief.descriptors.length; |
170 |
| - srcIndex++ |
171 |
| - ) { |
172 |
| - for ( |
173 |
| - let dstIndex = 0; |
174 |
| - dstIndex < destinationBrief.descriptors.length; |
175 |
| - dstIndex++ |
176 |
| - ) { |
177 |
| - const distance = getHammingDistance( |
178 |
| - sourceBrief.descriptors[srcIndex], |
179 |
| - destinationBrief.descriptors[dstIndex], |
180 |
| - ); |
181 |
| - result.push({ srcIndex, dstIndex, distance }); |
182 |
| - } |
183 |
| - } |
184 |
| - |
185 |
| - // 0-0 and 1-1 are the correct matches |
186 |
| - expect(result).toStrictEqual(data.expected); |
187 |
| -}); |
0 commit comments