Skip to content

Commit 2c05f82

Browse files
committed
Fix inverted resize check
Add a regression test
1 parent b3281b7 commit 2c05f82

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

apriltag_quad_thresh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ image_u8_t *threshold_bayer(apriltag_detector_t *td, image_u8_t *im)
15131513
unionfind_t* connected_components(apriltag_detector_t *td, image_u8_t* threshim, int w, int h, int ts) {
15141514
uint32_t maxid = w * h;
15151515
if (td->cached_uf) {
1516-
if (td->cached_uf->maxid <= maxid) {
1516+
if (td->cached_uf->maxid >= maxid) {
15171517
unionfind_reset(td->cached_uf);
15181518
} else {
15191519
unionfind_resize(td->cached_uf, maxid);

test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ endif()
4848

4949
add_test(NAME test_quick_decode COMMAND test_quick_decode)
5050

51+
add_executable(test_multiple_sizes test_multiple_sizes.c)
52+
target_link_libraries(test_multiple_sizes ${PROJECT_NAME})
53+
54+
add_test(NAME test_multiple_sizes
55+
COMMAND $<TARGET_FILE:test_multiple_sizes> data/33369213973_9d9bb4cc96_c.jpg
56+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
57+
)
58+

test/test_multiple_sizes.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <apriltag.h>
4+
#include <tag36h11.h>
5+
#include <common/pjpeg.h>
6+
7+
int main(int argc, char *argv[])
8+
{
9+
if (argc != 2) {
10+
fprintf(stderr, "Usage: %s <image.jpg>\n", argv[0]);
11+
return EXIT_FAILURE;
12+
}
13+
14+
pjpeg_t *pjpeg = pjpeg_create_from_file(argv[1], 0, NULL);
15+
if (pjpeg == NULL) {
16+
fprintf(stderr, "Failed to load %s\n", argv[1]);
17+
return EXIT_FAILURE;
18+
}
19+
image_u8_t *im = pjpeg_to_u8_baseline(pjpeg);
20+
21+
apriltag_family_t *tf = tag36h11_create();
22+
apriltag_detector_t *td = apriltag_detector_create();
23+
apriltag_detector_add_family(td, tf);
24+
td->refine_edges = false;
25+
26+
// First detect with quad_decimate=2
27+
td->quad_decimate = 2;
28+
zarray_t *dets1 = apriltag_detector_detect(td, im);
29+
int n1 = zarray_size(dets1);
30+
printf("decimate=2: %d detections\n", n1);
31+
apriltag_detections_destroy(dets1);
32+
33+
// Now detect with quad_decimate=1
34+
td->quad_decimate = 1;
35+
zarray_t *dets2 = apriltag_detector_detect(td, im);
36+
int n2 = zarray_size(dets2);
37+
printf("decimate=1: %d detections\n", n2);
38+
apriltag_detections_destroy(dets2);
39+
40+
image_u8_destroy(im);
41+
pjpeg_destroy(pjpeg);
42+
apriltag_detector_destroy(td);
43+
apriltag_detector_destroy(td2);
44+
tag36h11_destroy(tf);
45+
46+
if (n2 != n_ref) {
47+
fprintf(stderr, "FAIL: decimate 2->1 got %d detections, expected %d\n", n2, n_ref);
48+
return EXIT_FAILURE;
49+
}
50+
51+
printf("PASS\n");
52+
return EXIT_SUCCESS;
53+
}

0 commit comments

Comments
 (0)