# Mask Detection

This function block detects faces and classifies whether masks are worn correctly. It returns an annotated image for visual inspection and numeric counts for quick metrics.

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

`Image RGB`\
Image input to analyze. Accepts color images from cameras, files, or previous processing blocks.

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

`Image RGB`\
Annotated image with detection overlays for visualization.

`Masked`\
Count of faces detected with correct mask usage.

`Uncorrect Masked`\
Count of faces detected with masks worn incorrectly (e.g., nose uncovered).

`No Mask`\
Count of faces detected without a mask.

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

`Confidence Threshold %`\
Slider to adjust detection confidence. Increase to reduce false positives; decrease to find weaker detections. Use small adjustments to balance precision and recall for your scene.

## 🎯 Features <a href="#features" id="features"></a>

* Visual output with detection overlays for quick review.
* Numeric outputs for easy integration into logging, alarms, or dashboards.
* Runtime confidence tuning via the slider for adaptability to different lighting and distances.

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

1. Provide an image to the `Image RGB` input (live or static).
2. Adjust the `Confidence Threshold %` slider to the desired sensitivity.
3. Read the annotated image from the `Image RGB` output and the counts from `Masked`, `Uncorrect Masked`, and `No Mask` for downstream processing.

## ⚙️ Evaluation <a href="#evaluation" id="evaluation"></a>

When the block runs it analyzes the supplied image, annotates detected faces, and outputs the annotated image plus counts of each mask status. Use the confidence slider to tune detection behavior for your environment.

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

* For live camera input use `Camera USB`, `Camera IP (ONVIF)`, or `Stream Reader` as the image source to continuously analyze a stream.
* To inspect results visually while developing, route the annotated image to `Show Image`.
* If you need to process large frames faster, insert `Image Resize` before this block to reduce input size and increase throughput.
* Limit detection to a region of interest using `Image ROI`, `Image ROI Select`, or `Image ROI Polygon` to avoid irrelevant detections and speed up processing.
* Overlay or format detection output for presentations using `Draw Detections` to add rectangles and labels.
* Log or save suspicious frames with `Image Logger`, `Image Write`, or `Record Video` when counts exceed thresholds.
* Combine with `Object_Detection_Tracker` if you need to track mask status over time for the same person (use counts to trigger tracking or logging).
* For batch analysis of stored images, start with `Load Image` and then feed into this block for offline processing.

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

* No detections: try lowering `Confidence Threshold %`, ensure the input image is clear and well lit, or crop to the relevant area with `Image ROI`.
* Many false positives: raise `Confidence Threshold %`, use `Image Resize` to maintain appropriate scale, or restrict analysis with an ROI.
* Slow performance: downscale input with `Image Resize`, or run on fewer frames (skip frames upstream). Use `Image Logger` to capture only frames that meet conditions.
* Unreliable results under poor lighting: improve illumination, or apply preprocessing like `Denoising` and `Contrast Optimization` before feeding images into this block.


---

# 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/ai-blocks/mask-detection.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.
