I’ve made a few pipelines that are able to effectively track the balls, but the most helpful thing to know is how HSV (Hue, Saturation, Value) works, since HSV is how both Limelight and PhotonVision work. Also, I’ve found that having exposure and brightness up, while keeping the LEDs off has been the most consistent option for me, however I am working in a place consistently lighted with white light, but ultimately try to tune your input to have as much contrast as possible to make it easier for your thresholding. That said, having a working knowledge of HSV will make it easier to quicken the process.
In very quick terms, Hue is what color you are using (i.e., red), Saturation is how rich or full the color is (red with low saturation is more gray), and Value is how bright the color is (value 0 is black). This image sums it up well.
Since the red ball isn’t a full red, but rather a more dull red, the saturation will be more moderate, and since the ball is also kind of light, your value shouldn’t be too high either. However, I find it best to keep the top range of saturation to max, and the low parameter to about 3/4, because depending on lighting the ball will appear to have a more or less muted tone.
I’ve also found that since the ball has a fairly light color, It’s better to keep value set from max to maybe 10 units below whatever lets you fully detect the ball. Hue can be pretty specific because the ball is a very pure shape of red, it’s only the saturation and value that’s severely impacted by ambient lighting. I’ve found that keeping the value constraints fairly tight helps filter out bumpers to some degree, because they tend to be a very full red.
Once your thresholding is giving you a clear image of the ball, it’s time to contour filter!
It’s very important to keep these values as specific as possible while still keeping some room for error. Contour filtering applies to the rectangle that PhotonVision or Limelight thinks is a target. The 2 biggest factors of this are the W/H ratio and the Fullness of the blue rectangle. Keep area of the image at 0-100% so that you can detect at any range, but turn on speckle rejection all the way so that you filter out random pixels.
So, the W/H ratio. Since the image you should have after thresholding will be a fairly uniform circle, the Width to Height can be pretty close to 1:1 ratio, however, only a gibbous may filter depending on the ball’s shadow, so don’t do strictly 1:1, but close should do it.
For fullness of the rectangle, it’s fairly simple. Since the filtered image is a circle, the rectangle drawn around it won’t be 100% full because of the corners, so you don’t need to have it all the way at 100%, but it will be close because only the corners of the image will be empty. Doing this will eliminate most rectangles and squares. Hopefully that will get rid of your tracking issues.
However, if you are still having issues, the photonlib comes with a pretty nifty tool that lets you get the best target that most closely matches your parameters, so this can most likely also be fixed in code.
Hopefully this helps you out! Good luck with your vision!