Skip to content

Conversation

@shntu
Copy link
Contributor

@shntu shntu commented Dec 29, 2025

Description

This PR implements a new version of the camera focus block to provide improved focus measures across a wider range of images and use cases, including help adjusting exposure and aperture (focus metrics are also impacted by under/over-exposed images).

This PR contains a V2 workflow block that:

  1. Implements the the Tenengrad focus measure that is less sensitive to noise than the existing Brenner measure and provides a monotonically increasing value that is more useful for sorting + ranking images than Laplacian variance
  2. Accepts an optional list of detections to return the focus measure in specific bounding boxes, allowing users to measure the focus of objects of interest
  3. Displays an exposure histogram to the visualization to help differentiate between inadequate aperture/exposure settings and focusing that may be negatively impacting the sharpness of the image
  4. Provides an optional zebra stripe visualization to highlight overexposed and underexposed areas more prominently and some small conveniences like a grid and crosshairs for making sure the camera is aligned

Since this is a pretty significant change in behavior, this is a V2 with a new implementation.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

Tested this locally using a USB webcam below 👇

TestCameraFocusBlock.mp4

Tested using bounding box and label visualizations containing the focus measure of the boxes:

TestFocusBoxVis.mp4

Any specific deployment considerations

Since this is a classical CV block that uses a standard OpenCV Sobel operator on CPU, it can be deployed anywhere inference can run.

Docs

Currently, all documentation for this block is generated from code - I will be writing a followup blog post as part of Shipmas to update the information from this previous post: https://blog.roboflow.com/computer-vision-camera-focus/

@codeflash-ai
Copy link
Contributor

codeflash-ai bot commented Dec 29, 2025

⚡️ Codeflash found optimizations for this PR

📄 56% (0.56x) speedup for visualize_tenengrad_measure in inference/core/workflows/core_steps/classical_cv/camera_focus/v2.py

⏱️ Runtime : 52.1 milliseconds 33.3 milliseconds (best of 128 runs)

A dependent PR with the suggested changes has been created. Please review:

If you approve, it will be merged into this PR (branch camera-focus-v2).

Static Badge

shntu and others added 2 commits December 29, 2025 15:36
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
@codeflash-ai
Copy link
Contributor

codeflash-ai bot commented Dec 29, 2025

This PR is now faster! 🚀 Shantanu Bala accepted my code suggestion above.

@shntu
Copy link
Contributor Author

shntu commented Dec 29, 2025

⚡️ Codeflash found optimizations for this PR

📄 56% (0.56x) speedup for visualize_tenengrad_measure in inference/core/workflows/core_steps/classical_cv/camera_focus/v2.py

⏱️ Runtime : 52.1 milliseconds 33.3 milliseconds (best of 128 runs)

A dependent PR with the suggested changes has been created. Please review:

If you approve, it will be merged into this PR (branch camera-focus-v2).

Static Badge

I closed this PR - one of the suggestions was good (applied it) but some of the other suggestions didn't make sense (e.g. a cache for the values at the module level wouldn't improve performance since the images running through the pipeline would be different each time)

@shntu shntu closed this Dec 29, 2025
@shntu shntu reopened this Dec 29, 2025
@shntu shntu merged commit 70eefd4 into main Dec 30, 2025
51 checks passed
@shntu shntu deleted the camera-focus-v2 branch December 30, 2025 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants