Skip to content

Commit

Permalink
Fix the inconsistent image coordinate conventions used in the code: t…
Browse files Browse the repository at this point in the history
…he convention that (0,0) be the left top corner of the first pixel is adopted in this commit.

In the previous versions, the coordinate convention used for `quad_decimate=1, refine_edges=false` is already `left-top-corner=(0,0)`; while for `quad_decimate>1` or `refine_edges=true`, the convention is vague since it seems mixed conventions are used and [some code](#345 (comment)) even be wrong.

This fix ensures the same convention be used no matter what values for `quad_decimate` (=1 or >1) and `refine_edges`.
  • Loading branch information
NewThinker-Jeffrey committed Sep 6, 2024
1 parent 5666602 commit a62f434
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 7 additions & 11 deletions apriltag.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ static void refine_edges(apriltag_detector_t *td, image_u8_t *im_orig, struct qu
int steps_per_unit = 4;
double step_length = 1.0 / steps_per_unit;
int max_steps = 2 * steps_per_unit * range + 1;
double delta = 0.5;

// XXX tunable step size.
for (int step = 0; step < max_steps; ++step) {
Expand All @@ -810,8 +811,8 @@ static void refine_edges(apriltag_detector_t *td, image_u8_t *im_orig, struct qu
// gradient more precisely, but are more sensitive to
// noise.
double grange = 1;
double x1 = x0 + (n + grange)*nx;
double y1 = y0 + (n + grange)*ny;
double x1 = x0 + (n + grange)*nx - delta;
double y1 = y0 + (n + grange)*ny - delta;
int x1i = floor(x1);
int y1i = floor(y1);
double a1 = x1 - x1i;
Expand All @@ -820,8 +821,8 @@ static void refine_edges(apriltag_detector_t *td, image_u8_t *im_orig, struct qu
if (x1i < 0 || x1i + 1 >= im_orig->width || y1i < 0 || y1i + 1 >= im_orig->height)
continue;

double x2 = x0 + (n - grange)*nx;
double y2 = y0 + (n - grange)*ny;
double x2 = x0 + (n - grange)*nx - delta;
double y2 = y0 + (n - grange)*ny - delta;
int x2i = floor(x2);
int y2i = floor(y2);
double a2 = x2 - x2i;
Expand Down Expand Up @@ -1114,13 +1115,8 @@ zarray_t *apriltag_detector_detect(apriltag_detector_t *td, image_u8_t *im_orig)
zarray_get_volatile(quads, i, &q);

for (int j = 0; j < 4; j++) {
if (td->quad_decimate == 1.5) {
q->p[j][0] *= td->quad_decimate;
q->p[j][1] *= td->quad_decimate;
} else {
q->p[j][0] = (q->p[j][0] - 0.5)*td->quad_decimate + 0.5;
q->p[j][1] = (q->p[j][1] - 0.5)*td->quad_decimate + 0.5;
}
q->p[j][0] *= td->quad_decimate;
q->p[j][1] *= td->quad_decimate;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion apriltag_detect.docstring
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ a tuple containing the detections. Each detection is a dict with keys:

- id: integer identifying each detected tag

- center: pixel coordinates of the center of each detection
- center: pixel coordinates of the center of each detection. NOTE: Please be
cautious regarding the image coordinate convention. Here, we define (0,0) as
the left-top corner (not the center point) of the left-top-most pixel.

- lb-rb-rt-lt: pixel coordinates of the 4 corners of each detection. The order
is left-bottom, right-bottom, right-top, left-top
Expand Down

0 comments on commit a62f434

Please sign in to comment.