AprilRobotics / apriltag

AprilTag is a visual fiducial system popular for robotics research.
https://april.eecs.umich.edu/software/apriltag
Other
1.47k stars 522 forks source link

fix homography assert #325

Closed christian-rauch closed 1 month ago

christian-rauch commented 3 months ago

When the "Find best row to swap with." section in homography_compute2 would not find a value greater than 0 in a row, max_val_idx would stay -1 and maybe be used later to index a matrix. We protected against the negative indexing (in debug mode) by checking for a positive index in 3a0a155d5bc3bdcef34275f7c51f56e9cfd34e13.

But this causes issues for false-positive quad detections (#321). In this particular case, ignoreing the negative index would lead to return NULL; via max_val < epsilon, so we can also just return NULL; here and ignore that quad instead of stopping the process.

Fixes #321 .

@mkrogius As far as I understand c[4][4] contains the 4 correspondences from the 2D pixel coordinates in the image to the 2D coordinates of the unit square with +/-1 edge coordinates. But I don't fully understand why homography_compute2 does not deal with this special case of axis-aligned quads. Do you see a better way to handle this case?

mkrogius commented 2 months ago

Sorry for the delayed response (and also for my lack of activity on this repo for a long time). My intention was that the following if statement, the if (max_val < epsilon) { check, would handle any degenerate cases

mkrogius commented 2 months ago

As for the axis-aligned quads, I don't yet see why those would cause failure, since there should still be only one valid homography solution. I'll look a bit more next week