This repository was archived by the owner on Jul 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfeatureMatchingTest.ts
More file actions
128 lines (108 loc) · 3.14 KB
/
Copy pathfeatureMatchingTest.ts
File metadata and controls
128 lines (108 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import util from 'node:util';
import type { GetBriefOptions } from '../../src/featureMatching/descriptors/getBrief.js';
import { getBrief } from '../../src/featureMatching/descriptors/getBrief.js';
import type {
DrawKeypointsOptions,
GetColorsOptions,
} from '../../src/index.js';
import {
Montage,
getCrosscheckMatches,
readSync,
writeSync,
} from '../../src/index.js';
import { getMinMax } from '../../src/utils/getMinMax.js';
util.inspect.defaultOptions.depth = 5;
const getBriefOptions: GetBriefOptions = {
centroidPatchDiameter: 31,
bestKptRadius: 5,
};
// define the two images to analyse
const firstNumber = 1;
const secondNumber = 2;
const source = readSync(
`../../test/img/featureMatching/id-crops/crop${firstNumber}.png`,
).convertColor('GREY');
// fix contrast
const sourceExtremums = getMinMax(source);
source.level({
inputMin: sourceExtremums.min[0],
inputMax: sourceExtremums.max[0],
out: source,
});
const destination = readSync(
`../../test/img/featureMatching/id-crops/crop${secondNumber}.png`,
).convertColor('GREY');
// fix contrast
const destinationExtremums = getMinMax(destination);
destination.level({
inputMin: destinationExtremums.min[0],
inputMax: destinationExtremums.max[0],
out: destination,
});
console.log({
source: { width: source.width, height: source.height },
destination: { width: destination.width, height: destination.height },
});
const sourceBrief = getBrief(source, getBriefOptions);
const destinationBrief = getBrief(destination, getBriefOptions);
console.table(sourceBrief.keypoints);
console.log({
keypoints: {
sourceLength: sourceBrief.keypoints.length,
destinationLength: destinationBrief.keypoints.length,
},
descriptors: {
sourceLength: sourceBrief.descriptors.length,
destinationLength: destinationBrief.descriptors.length,
},
maxScore: {
source: sourceBrief.keypoints[0].score,
destination: destinationBrief.keypoints[0].score,
},
});
const crossMatches = getCrosscheckMatches(
sourceBrief.descriptors,
destinationBrief.descriptors,
);
console.log(`nb crosscheck matches: ${crossMatches.length}`);
const montage = new Montage(source, destination, {
scale: 2,
disposition: 'vertical',
});
const showDistanceOptions: GetColorsOptions = { minValueFactor: 0.2 };
// montage.drawMatches(
// matches,
// sourceBrief.keypoints,
// destinationBrief.keypoints,
// {
// showDistance: true,
// color: [255, 0, 0],
// circleDiameter: getBriefOptions.centroidPatchDiameter,
// showDistanceOptions,
// },
// );
montage.drawMatches(
crossMatches,
sourceBrief.keypoints,
destinationBrief.keypoints,
{
showDistance: true,
color: [0, 0, 255],
circleDiameter: getBriefOptions.centroidPatchDiameter,
showDistanceOptions,
},
);
const kptOptions: DrawKeypointsOptions = {
markerSize: 3,
color: [0, 255, 0],
showScore: true,
fill: true,
};
montage.drawKeypoints(sourceBrief.keypoints, kptOptions);
montage.drawKeypoints(destinationBrief.keypoints, {
...kptOptions,
origin: montage.destinationOrigin,
});
writeSync(`./results/result-${firstNumber}-${secondNumber}.png`, montage.image);
console.log('IMAGE WRITTEN TO DISK');