|
| 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