Need help with AprilTagPoseEstimater.Config()

So, we have a Logitech C270 plugged into our RoboRIO 2.

I’ve already written some code that can display a video stream in SmartDashboard. and it works just fine.

While writing some code for AprilTag detection, the AprilTagPoseEstimator.Config() required 5 parameters that I don’t know how to figure out the value of.

  • tagSize, apparently this is measured in meters? But what does that mean? I printed out some AprilTags on 8.5 by 11 in printer paper. Do I measure the length? width? area of the AprilTag?
  • fx, fy, cx, cy: I have contacted logitech support and even they do not know these exact specifications. Is there a software or something I can use to figure it out?
    fx = focal horizontal length
    fy = focal vertical length
    cx = center horizontal length
    cy = center vertical length

our github repo (on branch “AprilTagDetection”) navigate to → src/main → java/frc/robot → subsystems → vision →

EDIT: I forgot to mention but I am basing this off of This code sample provided by Peter_Johnson

Any help is greatly appreciated :>

tag size is the size of the black part of the tag – usually 6in, iirc?

fx fy cx cy should come from camera calibration, performed using opencv or . calibdb spits out camera calibration matrices – see here: OpenCV: Camera calibration With OpenCV for what the matrix has in it and stuff. Calibdb will give you a json like the one attached.
calib_microsoft__lifecam_hd_3000__045e_0810__1280.json (789 Bytes)


Basically, take the JSON spits out, and locate the correct indeces of the camera_matrix and copy paste into your code if that makes sense? The json encodes the matrix row-major


cx and cy are almost certainly half your cameras resolution in each direction.

fx and fy are probably about the same as each other.

you can figure out what they should be by making a target, say 0.2m across (so set tagsize to 0.2), and put it 1m in front of the camera. then adjust fx and fy so that the pose “z” is actually about 1.0.

that will get you unstuck.

1 Like

This will give you a valid camera matrix (and might be a way to get unstuck for a moment), but calibrating with like @thatmattguy suggested is not that difficult and will give a better result. I also think it’s probably faster to use. It will give a correct result without any of the fiddling and uncertainty associated with what’s basically guess and check.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.