> 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/tutorials/object-detection.md).

# Object Detection

This tutorial reads neural classifier results — the pipeline type used for game-piece detection (e.g. spotting a piece on the field before intaking it).

## 1. Switch to a classifier or detector pipeline

Configure the correct pipeline index in the Limelight web UI, or switch it from code:

```java
limelight.getSettings().withPipelineIndex(1).save();
```

## 2. Read results from the JSON payload

`getLatestResults()` returns the full frame, including whichever target arrays are populated for the active pipeline:

```java
limelight.getLatestResults().ifPresent((LimelightResults result) -> {
    for (NeuralClassifier object : result.targets_Classifier) {
        if (object.className.equals("algae") && object.confidence > 0.7) {
            // valid detection — object.tx / object.ty give position in the image
        }
    }
});
```

`targets_Classifier` is empty unless the active pipeline is a neural classifier pipeline — check `result.pipeline_type` if you're unsure which pipeline produced a frame.

## 3. Neural Detector: bounding boxes instead of whole-frame labels

If your pipeline is a **detector** (bounding boxes) rather than a **classifier** (whole-frame/zone label), read `targets_Detector` instead — same `LimelightResults` object, different array:

```java
limelight.getLatestResults().ifPresent((LimelightResults result) -> {
    for (NeuralDetector object : result.targets_Detector) {
        if (object.className.equals("coral")) {
            // object.tx / object.ty are crosshair-relative degrees, like an AprilTag result
            // object.ta is the bounding box area as a percentage of the image
        }
    }
});
```

## 4. Faster path: raw detections without JSON parsing

If you only need position and don't need `className`/`confidence`, `LimelightData.getRawDetections()` decodes the `rawdetections` NetworkTables entry directly — including the four bounding-box corners, which the JSON `NeuralDetector` result doesn't expose:

```java
for (RawDetection detection : limelight.getData().getRawDetections()) {
    // detection.classId, detection.txnc, detection.tync, detection.ta
    // detection.corner0_X .. detection.corner3_Y (pixel coordinates)
}
```

## Next steps

* [Target & Pipeline Types](/documentation/understanding/target-and-pipeline-types.md) — every target type and what pipeline produces it.
* [Results JSON vs. Raw NetworkTables](/documentation/understanding/results-json-vs-raw-networktables.md) — when to use `getLatestResults()` vs. the raw accessors.
* [Tuning a Neural Network Pipeline](/documentation/tuning/neural-network-pipeline-tuning.md) — confidence threshold and crop window.


---

# 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/tutorials/object-detection.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.
