# Camera USB Vidgear

This function block provides a flexible USB camera input for live image capture. Use it to scan, select and configure USB cameras, then stream frames into your processing graph. It is designed for continuous capture with simple controls for activation, release and resolution management.

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

`Activate Signal` Activate the camera and start returning frames (input socket)

`Release Signal` Release the camera and free resources (input socket)

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

`Image Any` Current camera frame (output socket)

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

`Scan Connected USB Cameras` Scan the system and list available USB cameras

`Select USB Camera` Dropdown to choose which detected camera to use

`Camera Resolution` Dropdown to choose a preferred capture resolution

`Current Resolution` Label showing the active resolution returned by the camera

`Open Advanced Setting` Opens the camera vendor/system settings dialog when available

`Message Area` Inline status messages and errors shown to the user

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

* Live USB camera capture suitable for production and testing scenarios.
* Easy discovery: scan and pick from connected cameras without leaving the interface.
* Resolution control: select common resolutions and the block shows the actual active resolution.
* Start / stop behavior via `Activate Signal` and `Release Signal` to manage resources.
* Graceful handling of temporary stream problems: the block preserves the last good frame, shows informative messages, and will attempt to recover the stream if possible.
* Optional background frame uploader support for asynchronous export or logging (if configured in your environment).
* Visual feedback: current status and helpful messages are displayed in the block UI.

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

* Click `Scan Connected USB Cameras` to populate the camera list, then choose a camera from `Select USB Camera`.
* Use `Camera Resolution` to request a preferred width/height; the `Current Resolution` label shows what the camera actually set.
* When `Activate Signal` is provided the block starts returning frames on the `Image Any` output. If the signal is not active, the block continues to hold and return the last captured frame.
* When `Release Signal` is provided the block stops the camera and frees the resource; the last available frame is still returned until the camera is reactivated.
* If the block encounters repeated blank/corrupted frames or a stream error, it will display an error message and attempt to recover or restart the camera automatically. This prevents silent failures in live scenarios.

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

1. Click `Scan Connected USB Cameras` to detect cameras.
2. Choose the desired camera using `Select USB Camera`.
3. Optionally select a resolution from `Camera Resolution`.
4. Send a `Activate Signal` to begin receiving frames from the `Image Any` output.
5. Send a `Release Signal` when you no longer need the camera to free the device.

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

* Preview live frames by connecting the `Image Any` output to the `Show Image` block for immediate visual feedback.
* To log or save frames, connect the `Image Any` output to `Image Logger`, `Image Write` or `Record Video`.
* If you need faster processing and can accept lower fidelity, insert `Image Resize` before heavy processing to reduce compute load.
* Improve detection robustness by inserting simple preprocessing such as `Blur`, `Denoising`, or `Auto Contrast` between the camera output and AI blocks.
* For targeted analysis use `Image ROI Select` or `Image ROI Polygon` to crop the scene before detection.
* Combine with AI blocks like `Object Detection`, `Mask Detection`, `Pose Estimation` or `Object Detection - Custom` to build inspection or analytics pipelines. For tracking use `Object_Detection_Tracker` after an object detection block.
* To publish results to external systems, route derived numeric/text outputs to `MQTT Publish` or `REST API - Post` blocks.
* If you see repeated black frames, try re-scanning the camera list or toggling the `Release Signal` to force a restart of the selected camera.

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

* No cameras listed after scan: confirm the camera is connected, powered and not exclusively used by another application. Re-scan after reconnecting.
* Camera fails to start or stream: check the selected camera in `Select USB Camera` and try a different resolution in `Camera Resolution`. Use `Release Signal` and then re-activate.
* Intermittent black or corrupted frames: the block keeps the last good frame to avoid gaps; if the problem persists, re-scan and re-select the camera or try a different USB port.
* Advanced camera controls not available: some camera vendor dialogs are platform-specific. Use the block’s resolution options or the camera’s system tools when advanced settings are required.

## 🔗 Example combinations <a href="#combination-examples" id="combination-examples"></a>

* Live monitoring: `Camera USB Vidgear` -> `Show Image`.
* Recording and post-analysis: `Camera USB Vidgear` -> `Record Video` and/or `Image Logger`; then feed recorded frames into `Find Object` or `Histogram On Line`.
* Inspection pipeline: `Camera USB Vidgear` -> `Image ROI Select` -> `Object Detection` -> `Object_Detection_Tracker` -> `Image Write`.

Use these combinations to build robust, real-time computer vision flows without touching implementation details.
