# Social Distance Detector

This function block analyzes an image stream to detect people and check physical distancing based on a distance threshold. It visualizes detected people and highlights pairs that violate the specified distance.

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

`Image Any` Feed the image or video frame to be analyzed.

`Perspective Matrix` Optional transformation matrix to convert image coordinates to a real-world plane for more accurate distance measurement.

`Distance Threshold` The minimum allowed distance between people (units depend on perspective calibration).

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

`Image Any` Annotated image with detected people, connecting lines, and violation highlights.

`Person Count` Number of people detected in the frame.

`Violation Count` Number of pairwise violations detected (pairs closer than threshold).

`Is Violated ?` Boolean indicating whether any violation exists.

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

`Confidence Ratio` Slider that adjusts detection confidence sensitivity. Higher values require stronger detection confidence to count as a person.

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

* Real-time person detection and visualization on incoming images.
* Pairwise distance measurement between detected people.
* Optional perspective correction using a provided `Perspective Matrix` for more accurate real-world distance checks.
* Clear outputs for monitoring and downstream processing: image, counts, and violation flag.

## 📊 Running mechanism <a href="#running-mechanism" id="running-mechanism"></a>

When active, this block receives the image input, detects person positions in the frame, optionally maps those positions using the provided `Perspective Matrix`, computes pairwise distances, and compares them to the provided `Distance Threshold`. The block returns an annotated image and numeric/boolean outputs describing detection and violation state.

## 📝 How to use <a href="#usage" id="usage"></a>

1. Provide an image source to `Image Any` (camera stream or loaded image).
2. If you need real-world distances, supply a calibrated `Perspective Matrix`. Without it, distance checks use image-plane units.
3. Set the desired `Distance Threshold` according to your calibration or approximate pixel distance.
4. Tune `Confidence Ratio` to balance missed detections vs false positives.
5. Read the outputs to trigger alerts, logs, or further processing when violations occur.

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

* For camera input, pair this block with an image source such as `Camera USB`, `Camera IP (ONVIF)`, `Stream Reader`, or `Load Image`.
* To preview results in a larger view, add `Show Image` after this block.
* If detection is noisy, try resizing or denoising the image beforehand using `Image Resizer` or `Denoising` to improve stability.
* For more robust person detection or custom classes, consider combining with `Object Detection` or `Object Detection - Custom` upstream and feed detected centers into this block for distance checking.
* Use `Perspective Transform` to produce a reliable `Perspective Matrix` when you need real-world distances.
* Use `Image ROI` or `Image ROI Select` to limit the analysis area (reduce false detections and speed up processing).
* When tracking is required across frames, use `Object_Detection_Tracker` downstream to get persistent IDs and improved analytics.

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

* No people detected: increase `Confidence Ratio` slightly or provide higher-resolution input. Ensure the scene lighting allows for clear person outlines.
* Many false positives: try increasing `Confidence Ratio`, apply preprocessing like `Blur` or `Image Threshold`, or restrict the area with `Image ROI`.
* Distance measurements seem incorrect: verify the calibration and provide a correct `Perspective Matrix` using `Perspective Transform`. Without perspective correction, distances are in image pixels and may not reflect real-world values.
* High CPU/GPU load: reduce input resolution with `Image Resizer` or run detection less frequently.


---

# 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/social-distance-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.
