1
+ import { TestImagePath } from '../../../../test/TestImagePath' ;
1
2
import { ImageColorModel } from '../../../Image' ;
2
3
import { drawKeypoints } from '../../visualize/drawKeypoints' ;
3
4
import { getOrientedFastKeypoints } from '../getOrientedFastKeypoints' ;
4
5
5
- test ( '7x7 image, angle = 90°' , ( ) => {
6
+ test ( '7x7 image, angle = - 90°' , ( ) => {
6
7
const image = testUtils . createGreyImage ( [
7
8
[ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
8
9
[ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
@@ -15,7 +16,45 @@ test('7x7 image, angle = 90°', () => {
15
16
16
17
const result = getOrientedFastKeypoints ( image ) [ 0 ] ;
17
18
expect ( result ) . toStrictEqual ( {
18
- angle : 90 ,
19
+ angle : - 90 ,
20
+ origin : { row : 3 , column : 3 } ,
21
+ score : 2780 ,
22
+ } ) ;
23
+ } ) ;
24
+
25
+ test ( '7x7 image, angle = 135°' , ( ) => {
26
+ const image = testUtils . createGreyImage ( [
27
+ [ 100 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
28
+ [ 0 , 100 , 0 , 0 , 0 , 0 , 0 ] ,
29
+ [ 0 , 0 , 100 , 0 , 0 , 0 , 0 ] ,
30
+ [ 0 , 0 , 0 , 200 , 0 , 0 , 0 ] ,
31
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
32
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
33
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
34
+ ] ) ;
35
+
36
+ const result = getOrientedFastKeypoints ( image ) [ 0 ] ;
37
+ expect ( result ) . toStrictEqual ( {
38
+ angle : - 225 ,
39
+ origin : { row : 3 , column : 3 } ,
40
+ score : 2780 ,
41
+ } ) ;
42
+ } ) ;
43
+
44
+ test ( '7x7 image, angle = -135°' , ( ) => {
45
+ const image = testUtils . createGreyImage ( [
46
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
47
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
48
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
49
+ [ 0 , 0 , 0 , 200 , 0 , 0 , 0 ] ,
50
+ [ 0 , 0 , 100 , 0 , 0 , 0 , 0 ] ,
51
+ [ 0 , 100 , 0 , 0 , 0 , 0 , 0 ] ,
52
+ [ 100 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
53
+ ] ) ;
54
+
55
+ const result = getOrientedFastKeypoints ( image ) [ 0 ] ;
56
+ expect ( result ) . toStrictEqual ( {
57
+ angle : 225 ,
19
58
origin : { row : 3 , column : 3 } ,
20
59
score : 2780 ,
21
60
} ) ;
@@ -53,12 +92,12 @@ test('7x7 image, angle = 0°', () => {
53
92
54
93
const result = getOrientedFastKeypoints ( image ) [ 0 ] ;
55
94
expect ( result ) . toStrictEqual ( {
56
- angle : 0 ,
95
+ angle : - 0 ,
57
96
origin : { row : 3 , column : 3 } ,
58
97
score : 2680 ,
59
98
} ) ;
60
99
} ) ;
61
- test ( '7x7 image, angle = - 45°' , ( ) => {
100
+ test ( '7x7 image, angle = 45°' , ( ) => {
62
101
const image = testUtils . createGreyImage ( [
63
102
[ 0 , 0 , 0 , 0 , 0 , 0 , 100 ] ,
64
103
[ 0 , 0 , 0 , 0 , 0 , 100 , 0 ] ,
@@ -69,6 +108,25 @@ test('7x7 image, angle = -45°', () => {
69
108
[ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
70
109
] ) ;
71
110
111
+ const result = getOrientedFastKeypoints ( image ) [ 0 ] ;
112
+ expect ( result ) . toBeDeepCloseTo ( {
113
+ angle : 45 ,
114
+ origin : { row : 3 , column : 3 } ,
115
+ score : 2780 ,
116
+ } ) ;
117
+ } ) ;
118
+
119
+ test ( '7x7 image, angle = -45°' , ( ) => {
120
+ const image = testUtils . createGreyImage ( [
121
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
122
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
123
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
124
+ [ 0 , 0 , 0 , 200 , 0 , 0 , 0 ] ,
125
+ [ 0 , 0 , 0 , 0 , 100 , 0 , 0 ] ,
126
+ [ 0 , 0 , 0 , 0 , 0 , 100 , 0 ] ,
127
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 100 ] ,
128
+ ] ) ;
129
+
72
130
const result = getOrientedFastKeypoints ( image ) [ 0 ] ;
73
131
expect ( result ) . toBeDeepCloseTo ( {
74
132
angle : - 45 ,
@@ -77,6 +135,44 @@ test('7x7 image, angle = -45°', () => {
77
135
} ) ;
78
136
} ) ;
79
137
138
+ test ( 'patch with one keypoint' , ( ) => {
139
+ const image = testUtils . load ( 'featureMatching/patch.png' ) . invert ( ) ;
140
+
141
+ const keypoints = getOrientedFastKeypoints ( image ) ;
142
+
143
+ expect (
144
+ drawKeypoints ( image , keypoints , { markerSize : 7 , showOrientation : true } ) ,
145
+ ) . toMatchImageSnapshot ( ) ;
146
+
147
+ expect ( keypoints ) . toBeDeepCloseTo ( [
148
+ {
149
+ angle : - 187.205 ,
150
+ origin : { row : 15 , column : 14 } ,
151
+ score : 3290 ,
152
+ } ,
153
+ ] ) ;
154
+ } ) ;
155
+
156
+ test ( 'patch with one keypoint, centroidPatchDiameter=15' , ( ) => {
157
+ const image = testUtils . load ( 'featureMatching/patch.png' ) . invert ( ) ;
158
+
159
+ const keypoints = getOrientedFastKeypoints ( image , {
160
+ centroidPatchDiameter : 15 ,
161
+ } ) ;
162
+
163
+ expect (
164
+ drawKeypoints ( image , keypoints , { markerSize : 7 , showOrientation : true } ) ,
165
+ ) . toMatchImageSnapshot ( ) ;
166
+
167
+ expect ( keypoints ) . toBeDeepCloseTo ( [
168
+ {
169
+ angle : 191.8 ,
170
+ origin : { row : 15 , column : 14 } ,
171
+ score : 3290 ,
172
+ } ,
173
+ ] ) ;
174
+ } ) ;
175
+
80
176
test ( 'check we handle edge cases properly' , ( ) => {
81
177
const image = testUtils
82
178
. load ( 'featureMatching/crop1.png' )
@@ -98,111 +194,42 @@ test('angle should never be NaN', () => {
98
194
}
99
195
} ) ;
100
196
101
- test ( 'check angle for different windowSize' , ( ) => {
102
- const image = testUtils
103
- . load ( 'featureMatching/polygons/scaleneTriangle10.png' )
104
- . convertColor ( ImageColorModel . GREY ) ;
105
-
106
- const keypoints7 = getOrientedFastKeypoints ( image ) ;
107
- const keypoints15 = getOrientedFastKeypoints ( image , { windowSize : 15 } ) ;
108
- const keypoints31 = getOrientedFastKeypoints ( image , { windowSize : 31 } ) ;
109
-
110
- expect ( [ keypoints7 , keypoints15 , keypoints31 ] ) . toBeDeepCloseTo (
111
- [
112
- [
113
- {
114
- origin : { row : 607 , column : 132 } ,
115
- score : 2680 ,
116
- angle : 145.3 ,
117
- } ,
118
- {
119
- origin : { row : 50 , column : 292 } ,
120
- score : 2662 ,
121
- angle : - 112.2 ,
122
- } ,
123
- ] ,
124
- [
125
- {
126
- origin : { row : 607 , column : 132 } ,
127
- score : 2680 ,
128
- angle : 123.7 ,
129
- } ,
130
- {
131
- origin : { row : 50 , column : 292 } ,
132
- score : 2662 ,
133
- angle : - 95.4 ,
134
- } ,
135
- ] ,
136
- [
137
- {
138
- origin : { row : 607 , column : 132 } ,
139
- score : 2680 ,
140
- angle : 120 ,
141
- } ,
142
- {
143
- origin : { row : 50 , column : 292 } ,
144
- score : 2662 ,
145
- angle : - 92.1 ,
146
- } ,
147
- ] ,
148
- ] ,
149
- 1 ,
150
- ) ;
151
- } ) ;
152
-
153
- test ( 'angle diff should be 90°' , ( ) => {
154
- const windowSize = 15 ;
155
- const markerSize = 15 ;
197
+ test . each ( [
198
+ {
199
+ message : 'betterScaleneTriangle' ,
200
+ image : 'betterScaleneTriangle' ,
201
+ } ,
202
+ {
203
+ message : 'betterScaleneTriangle90' ,
204
+ image : 'betterScaleneTriangle90' ,
205
+ } ,
206
+ ] ) ( 'orientation should look correct ($message)' , ( data ) => {
207
+ const markerSize = 7 ;
156
208
157
209
const image = testUtils
158
- . load ( 'featureMatching/polygons/betterScaleneTriangle.png' )
159
- . convertColor ( ImageColorModel . GREY ) ;
160
-
161
- const rotated = testUtils
162
- . load ( 'featureMatching/polygons/betterScaleneTriangle90.png' )
163
- . convertColor ( ImageColorModel . GREY ) ;
164
-
165
- const keypoints = getOrientedFastKeypoints ( image , { windowSize } ) ;
166
- const keypointsRotated = getOrientedFastKeypoints ( rotated , { windowSize } ) ;
167
- console . log ( keypoints , keypointsRotated ) ;
210
+ . load ( `featureMatching/polygons/${ data . image } .png` as TestImagePath )
211
+ . convertColor ( ImageColorModel . GREY )
212
+ . invert ( ) ;
213
+ const keypoints = getOrientedFastKeypoints ( image ) ;
168
214
169
215
expect (
170
216
drawKeypoints ( image , keypoints , { markerSize, showOrientation : true } ) ,
171
217
) . toMatchImageSnapshot ( ) ;
172
- expect (
173
- drawKeypoints ( rotated , keypointsRotated , {
174
- markerSize,
175
- showOrientation : true ,
176
- } ) ,
177
- ) . toMatchImageSnapshot ( ) ;
218
+ } ) ;
178
219
179
- expect ( [ keypoints , keypointsRotated ] ) . toBeDeepCloseTo (
180
- [
181
- [
182
- {
183
- origin : { row : 607 , column : 132 } ,
184
- score : 2680 ,
185
- angle : 145.3 ,
186
- } ,
187
- {
188
- origin : { row : 50 , column : 292 } ,
189
- score : 2662 ,
190
- angle : - 112.2 ,
191
- } ,
192
- ] ,
193
- [
194
- {
195
- origin : { row : 607 , column : 132 } ,
196
- score : 2680 ,
197
- angle : 123.7 ,
198
- } ,
199
- {
200
- origin : { row : 50 , column : 292 } ,
201
- score : 2662 ,
202
- angle : - 95.4 ,
203
- } ,
204
- ] ,
205
- ] ,
206
- 1 ,
207
- ) ;
220
+ test ( 'check angle for different windowSize' , ( ) => {
221
+ const image = testUtils
222
+ . load ( 'featureMatching/polygons/scaleneTriangle10.png' )
223
+ . convertColor ( ImageColorModel . GREY )
224
+ . invert ( ) ;
225
+
226
+ const angle77 = getOrientedFastKeypoints ( image ) [ 0 ] . angle ;
227
+ const angle15 = getOrientedFastKeypoints ( image , {
228
+ centroidPatchDiameter : 15 ,
229
+ } ) [ 0 ] . angle ;
230
+ const angle31 = getOrientedFastKeypoints ( image , {
231
+ centroidPatchDiameter : 31 ,
232
+ } ) [ 0 ] . angle ;
233
+
234
+ expect ( [ angle77 , angle15 , angle31 ] ) . toBeDeepCloseTo ( [ 69.81 , 62.84 , 61.79 ] , 0 ) ;
208
235
} ) ;
0 commit comments