Most FTC vision tasks reduce to: convert colour space, threshold, find the largest contour, and decide which zone it falls in. Keep it that simple and it will survive venue lighting.
Pipeline skeletonLink to this section
public class PropPipeline extends OpenCvPipeline {
private final Mat hsv = new Mat();
private final Mat mask = new Mat();
public volatile int zone = 2;
@Override
public Mat processFrame(Mat input) {
Imgproc.cvtColor(input, hsv, Imgproc.COLOR_RGB2HSV);
Core.inRange(hsv, new Scalar(0, 120, 70), new Scalar(10, 255, 255), mask);
List<MatOfPoint> contours = new ArrayList<>();
Imgproc.findContours(mask, contours, new Mat(),
Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
double best = 0;
for (MatOfPoint c : contours) {
Rect r = Imgproc.boundingRect(c);
if (r.area() > best && r.area() > 1500) {
best = r.area();
zone = r.x < input.width() / 3 ? 1 : r.x < 2 * input.width() / 3 ? 2 : 3;
}
}
return input;
}
}Lighting disciplineLink to this section
- Work in HSV, never RGB — hue survives brightness changes.
- Record footage at the venue during practice and replay it offline.
- Reject contours below a minimum area to kill noise.