> For the complete documentation index, see [llms.txt](https://yall.yassrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yall.yassrobotics.com/documentation/tuning/retroreflective-pipeline-tuning.md).

# Tuning a Retroreflective Pipeline

A retroreflective pipeline finds targets in two sequential stages: an HSV color threshold turns the image into a binary mask, then contour filtering/sorting picks which blob(s) in that mask are the real target. Tune them in that order — filtering a noisy mask is much harder than filtering a clean one.

{% hint style="info" %}
Do the [camera sensor settings](/documentation/tuning/camera-sensor-settings.md) pass first. A properly dark, low-exposure image makes the threshold step below almost trivial.
{% endhint %}

## Stage 1 — HSV color threshold

Switch the web UI's video feed to **threshold** view so you can see the binary mask update live while you tune.

| Slider         | What it does                                                                                                                 |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| **Hue**        | The "pure" color, independent of brightness (0 = red, \~59 = green). Tune this first — it's the most discriminating channel. |
| **Saturation** | Color purity — how washed-out (low) vs. pure (high) the color is.                                                            |
| **Value**      | Brightness — how much black is mixed in.                                                                                     |

Workflow:

1. Use the **eyedropper** tool on the target in the raw camera feed to center the HSV range on it automatically.
2. Refine with the **add**/**subtract** wands rather than dragging sliders blindly.
3. **Raise the minimum Value off of zero.** Leaving it at `0` passes black pixels through the mask, which is almost never what you want.
4. Keep every range **as small as possible** — the tighter the range, the more portable the pipeline is to other fields/lighting rigs.
5. If tracking a red target, enable hue inversion (red wraps around both ends of the hue range).

## Stage 2 — Contour filtering and sorting

Once the mask is clean, filter which contours in it count as "the target," in this order:

1. **Target Area** — eliminates obviously-wrong-size blobs first (stadium lights, scoreboard displays). The area slider is quartically scaled, giving finer control at the low end where real FRC targets usually sit.
2. **Target Aspect Ratio** — width ÷ height of the bounding rectangle; discriminates target shape (tall vs. wide). Also nonlinearly scaled.
3. **Target Fullness** — percentage of active pixels inside the bounding rectangle; solid targets approach `1.0`, hollow/U-shaped targets read lower. Use this to reject partial detections that passed area/aspect-ratio by coincidence.
4. **Sort Mode** — how to pick among multiple contours that still pass every filter above. `closest` picks the one nearest the (calibrated) crosshair — usually what you want for aiming.
5. **Target Grouping** — enable dual/tri mode if your real target is made of multiple retroreflective shapes that should be tracked as one.
6. **Smart Speckle Rejection** — apply last, to reject small, close-range artifacts (e.g. LEDs). This is an outlier filter, not a primary one.

{% hint style="warning" %}
Lean on area/aspect-ratio/fullness to do the real work. Outlier rejection (speckle rejection, smart grouping) works *against* you if the individual filters are loose — it starts throwing away legitimate detections instead of noise.
{% endhint %}

## See Also

* [Tuning Workflow Overview](/documentation/tuning/tuning-workflow-overview.md)
* [Target & Pipeline Types](/documentation/understanding/target-and-pipeline-types.md) — `RetroreflectiveTape`, the typed result this pipeline feeds into `LimelightResults`.
* [Crosshair Calibration](/documentation/tuning/crosshair-calibration.md) — needed before "closest" sort mode means what you expect.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://yall.yassrobotics.com/documentation/tuning/retroreflective-pipeline-tuning.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
