10
10
11
11
import edu .wpi .first .math .geometry .Transform3d ;
12
12
import edu .wpi .first .math .util .Units ;
13
+ import edu .wpi .first .util .PixelFormat ;
14
+ import edu .wpi .first .util .RawFrame ;
13
15
import edu .wpi .first .util .RuntimeLoader ;
14
16
import java .io .ByteArrayOutputStream ;
15
17
import java .io .IOException ;
@@ -132,7 +134,7 @@ public Mat loadImage(String resource) throws IOException {
132
134
}
133
135
134
136
@ Test
135
- void testDecodeCropped () {
137
+ void testDecodeAndPose () {
136
138
detector .addFamily ("tag16h5" );
137
139
detector .addFamily ("tag36h11" );
138
140
@@ -144,35 +146,14 @@ void testDecodeCropped() {
144
146
return ;
145
147
}
146
148
147
- // Pre-knowledge -- the tag is within this ROI of this particular test image
148
- var cropped = image .submat (100 , 400 , 220 , 570 );
149
-
150
- try {
151
- AprilTagDetection [] results = detector .detect (cropped );
152
- assertEquals (1 , results .length );
153
- assertEquals ("tag36h11" , results [0 ].getFamily ());
154
- assertEquals (1 , results [0 ].getId ());
155
- assertEquals (0 , results [0 ].getHamming ());
156
- } finally {
157
- cropped .release ();
158
- image .release ();
159
- }
160
- }
149
+ var frameBytes = new byte [image .width () * image .height ()];
150
+ image .get (0 , 0 , frameBytes );
161
151
162
- @ Test
163
- void testDecodeAndPose () {
164
- detector .addFamily ("tag16h5" );
165
- detector .addFamily ("tag36h11" );
152
+ var frame = new RawFrame ();
153
+ frame .setData (frameBytes , image .width (), image .height (), 1 , PixelFormat .kGray );
166
154
167
- Mat image ;
168
155
try {
169
- image = loadImage ("tag1_640_480.jpg" );
170
- } catch (IOException ex ) {
171
- fail (ex );
172
- return ;
173
- }
174
- try {
175
- AprilTagDetection [] results = detector .detect (image );
156
+ AprilTagDetection [] results = detector .detect (frame );
176
157
assertEquals (1 , results .length );
177
158
assertEquals ("tag36h11" , results [0 ].getFamily ());
178
159
assertEquals (1 , results [0 ].getId ());
@@ -204,8 +185,15 @@ void testPoseRotatedX() {
204
185
fail (ex );
205
186
return ;
206
187
}
188
+
189
+ var frameBytes = new byte [image .width () * image .height ()];
190
+ image .get (0 , 0 , frameBytes );
191
+
192
+ var frame = new RawFrame ();
193
+ frame .setData (frameBytes , image .width (), image .height (), 1 , PixelFormat .kGray );
194
+
207
195
try {
208
- AprilTagDetection [] results = detector .detect (image );
196
+ AprilTagDetection [] results = detector .detect (frame );
209
197
assertEquals (1 , results .length );
210
198
211
199
var estimator =
@@ -237,8 +225,15 @@ void testPoseRotatedY() {
237
225
fail (ex );
238
226
return ;
239
227
}
228
+
229
+ var frameBytes = new byte [image .width () * image .height ()];
230
+ image .get (0 , 0 , frameBytes );
231
+
232
+ var frame = new RawFrame ();
233
+ frame .setData (frameBytes , image .width (), image .height (), 1 , PixelFormat .kGray );
234
+
240
235
try {
241
- AprilTagDetection [] results = detector .detect (image );
236
+ AprilTagDetection [] results = detector .detect (frame );
242
237
assertEquals (1 , results .length );
243
238
244
239
var estimator =
@@ -267,8 +262,15 @@ void testPoseStraightOn() {
267
262
fail (ex );
268
263
return ;
269
264
}
265
+
266
+ var frameBytes = new byte [image .width () * image .height ()];
267
+ image .get (0 , 0 , frameBytes );
268
+
269
+ var frame = new RawFrame ();
270
+ frame .setData (frameBytes , image .width (), image .height (), 1 , PixelFormat .kGray );
271
+
270
272
try {
271
- AprilTagDetection [] results = detector .detect (image );
273
+ AprilTagDetection [] results = detector .detect (frame );
272
274
assertEquals (1 , results .length );
273
275
274
276
var estimator =
0 commit comments