|
1 | 1 | import { ImageColorModel, Image, ImageCoordinates } from '../../../Image';
|
2 | 2 | import { getOrientedFastKeypoints } from '../../keypoints/getOrientedFastKeypoints';
|
| 3 | +import { getHammingDistance } from '../../matching/getHammingDistance'; |
3 | 4 | import { drawKeypoints } from '../../visualize/drawKeypoints';
|
4 | 5 | import { getBriefDescriptors } from '../getBriefDescriptors';
|
5 | 6 |
|
@@ -111,3 +112,46 @@ test('verify descriptor is correct (descriptorLength = 10)', () => {
|
111 | 112 | new Uint8Array([0, 0, 0, 0, 0, 0, 1, 0, 1, 0]),
|
112 | 113 | );
|
113 | 114 | });
|
| 115 | + |
| 116 | +test.only('compare scalene triangle keypoints', () => { |
| 117 | + const source = testUtils |
| 118 | + .load('featureMatching/polygons/scaleneTriangle.png') |
| 119 | + .convertColor(ImageColorModel.GREY); |
| 120 | + const sourceKeypoints = getOrientedFastKeypoints(source); |
| 121 | + const sourceBrief = getBriefDescriptors(source, sourceKeypoints); |
| 122 | + const destination = testUtils |
| 123 | + .load('featureMatching/polygons/scaleneTriangle10.png') |
| 124 | + .convertColor(ImageColorModel.GREY); |
| 125 | + const destinationKeypoints = getOrientedFastKeypoints(destination); |
| 126 | + const destinationBrief = getBriefDescriptors( |
| 127 | + destination, |
| 128 | + destinationKeypoints, |
| 129 | + ); |
| 130 | + let result = []; |
| 131 | + |
| 132 | + for ( |
| 133 | + let srcIndex = 0; |
| 134 | + srcIndex < sourceBrief.descriptors.length; |
| 135 | + srcIndex++ |
| 136 | + ) { |
| 137 | + for ( |
| 138 | + let dstIndex = 0; |
| 139 | + dstIndex < destinationBrief.descriptors.length; |
| 140 | + dstIndex++ |
| 141 | + ) { |
| 142 | + const distance = getHammingDistance( |
| 143 | + sourceBrief.descriptors[srcIndex], |
| 144 | + destinationBrief.descriptors[dstIndex], |
| 145 | + ); |
| 146 | + result.push({ srcIndex, dstIndex, distance }); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 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 | + ]); |
| 157 | +}); |
0 commit comments