Skip to content

Commit 26f3626

Browse files
committed
[apriltag] Fix AprilTagDetector cols/stride mixup
1 parent 4c225ef commit 26f3626

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public void clearFamilies() {
297297
* @return Results (array of AprilTagDetection)
298298
*/
299299
public AprilTagDetection[] detect(Mat img) {
300-
return AprilTagJNI.detect(m_native, img.cols(), img.rows(), img.cols(), img.dataAddr());
300+
return AprilTagJNI.detect(m_native, img.cols(), img.rows(), (int)img.step1(), img.dataAddr());
301301
}
302302

303303
private long m_native;

apriltag/src/test/java/edu/wpi/first/apriltag/AprilTagDetectorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ public Mat loadImage(String resource) throws IOException {
131131
return image;
132132
}
133133

134+
@Test
135+
void testDecodeCropped() {
136+
detector.addFamily("tag16h5");
137+
detector.addFamily("tag36h11");
138+
139+
Mat image;
140+
try {
141+
image = loadImage("tag1_640_480.jpg");
142+
} catch (IOException ex) {
143+
fail(ex);
144+
return;
145+
}
146+
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+
}
161+
134162
@Test
135163
void testDecodeAndPose() {
136164
detector.addFamily("tag16h5");

0 commit comments

Comments
 (0)