# Feature Detector

This function block finds an object in a live or static image by matching features from a provided training image. It compares distinctive points between the training image and the input image, attempts to estimate the object's position and rotation, and provides a visual and numeric result.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Train Image` The reference image that contains the object to detect. Provide a clear, well-lit crop of the object.

`Input Image From Camera` The image where the block will search for the object (live camera frame or loaded image).

These are input sockets.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Detected Image` The input image annotated with detection graphics (e.g., contour and center) when the object is found.

`Detect Status` A boolean indicating whether the object was detected (true/false).

`Center` The (x, y) coordinates of the detected object's center.

These are output sockets.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Homography Type` Choose the method used for estimating the geometric transform between images.

`Compute Type` Select the internal computation preference (quality vs performance).

`Number of features` How many keypoints/features to detect in the training image.

`Distance Threshold` Tolerance used when matching features (affects match acceptance).

`K nearest` Number of nearest matches considered when comparing descriptors.

`Pyramid Decrease Ratio` Controls scale down steps for multi-scale detection.

`Pyramid Levels` Number of pyramid levels used in multi-scale processing.

`Point Compare Type` Internal parameter affecting how points are compared.

These are widgets you can tune to adjust detection behavior.

## ⚙️ How it runs <a href="#running-mechanism" id="running-mechanism"></a>

* The block extracts features from the provided `Train Image` using the chosen feature/computation settings.
* It then searches the `Input Image From Camera` for matching features and attempts to estimate the object's location and orientation.
* If a valid transformation is found, the block annotates the input image with a bounding contour and a center point, sets `Detect Status` to true, and outputs the detected center coordinates.
* If no valid match is found, `Detect Status` is false and `Center` is returned as a default coordinate.

The block continuously evaluates when connected to live sources, so tuning controls will update behavior in near real time.

## ✨ Key features <a href="#features" id="features"></a>

* Robust feature-based detection that handles rotation and scale changes.
* Multi-parameter tuning for quality vs performance trade-offs.
* Visual feedback via an annotated `Detected Image` to confirm results.
* Outputs both a boolean status and exact center position for downstream logic.

## 📝 Usage instructions <a href="#usage" id="usage"></a>

1. Provide a clear cropped example of the object to `Train Image`. Prefer images with distinct textures or corners.
2. Connect a camera frame or image to `Input Image From Camera`.
3. Start with moderate values: set `Number of features` to a few hundred and `Distance Threshold` to a middle value.
4. Run the system and observe the `Detected Image`. Adjust `Homography Type`, `Number of features`, `Distance Threshold`, and `K nearest` to improve reliability.
5. Use the boolean `Detect Status` to trigger actions (logging, saving, counting) or feed the `Center` into other blocks.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* If object and camera scales differ, use `Image Resize` before this block so the training image and input image are closer in scale.
* Crop the search area with `Image ROI Select` to speed up detection and avoid false matches from cluttered backgrounds.
* Improve robustness under noisy conditions with `Blur` to remove high-frequency noise, or use `Contrast Optimization` to enhance contrast before detection.
* Use `Show Image` to preview detection results interactively while you tune controls.
* For drawing and reporting results, combine with `Draw Detections` to overlay detections cleanly on output images.
* If template-based matching is more suitable for your object, consider trying the `Find Object` block as an alternative or complementary approach.
* To store examples or results for offline review, pair with `Image Logger`.

(hints above refer to available function blocks you can combine in a flow.)

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* No detection: increase `Number of features`, relax `Distance Threshold`, or provide a clearer training image. Try different `Homography Type` values.
* False positives: reduce `Number of features` or tighten `Distance Threshold`. Crop the image using `Image ROI Select` to eliminate confusing backgrounds.
* Slow performance: lower `Number of features`, reduce pyramid levels, or run a smaller search region. Preprocess with `Image Resize` to reduce input dimensions.
* Poor results under low contrast: apply `Contrast Optimization` first or capture a higher-quality training image.

If results remain inconsistent, iterate: adjust controls incrementally and use `Show Image` to visually confirm the changes.


---

# Agent Instructions: 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:

```
GET https://docs.augelab.com/function-blocks/detections-shapes/detectors/feature-detector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
