Skip to content

Commit 05bcde0

Browse files
committed
Fix inverted resize check
Add a regression test
1 parent b3281b7 commit 05bcde0

File tree

3 files changed

+65
-1
lines changed

3 files changed

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

0 commit comments

Comments
 (0)