Tuna Gül

Systems

Two-camera distance to targets Archive

Distance to the reflective FRC targets from two cheap cameras, without a full stereo calibration. Blobs are paired across the two frames, and distance is fitted against 1/disparity from real measurements.

Role
Main author
Period
Jan–Mar 2023
Team
Team NF (FRC 9029)
Stack
Python · OpenCV · NumPy
Impact
A straight-line fit alone gave r ≈ 0.99

Why

Our FRC robot needed the distance to the reflective targets on the field. My teammates and I had two cheap cameras, and instead of a full stereo calibration we measured.

What I did

I wrote the vision code by hand, in Python with OpenCV:

  • Finding targets: HSV thresholding, erode and dilate, then contours, keeping the blobs that fill enough of their rotated bounding box.
  • Pairing: a blob in the left frame is paired with the blob in the right frame whose contour area is most similar, if the smaller area is at least 0.8 of the larger.
  • Distance: the disparity is the distance between the two paired centroids. Distance is a third-degree polynomial in 1/disparity, fitted to distances we measured.

Results

A straight line in 1/disparity already fitted with r = 0.9934, which is what the pinhole model (distance = focal length × baseline / disparity) predicts. The fit was checked with R² on a second data set taken at an angle.

The code is in private team repositories, so there is no link.