Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lens focus assist tool #1597

Open
jlmcmchl opened this issue Nov 20, 2024 · 2 comments
Open

Add a lens focus assist tool #1597

jlmcmchl opened this issue Nov 20, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@jlmcmchl
Copy link
Contributor

jlmcmchl commented Nov 20, 2024

Is your feature request related to a problem? Please describe.
I made a tool that reports the tenengrad* metric for a central region of interest in a captured frame, and plots that information for use when tuning camera focus. It's written in python, but I'd like to add it to PV because PV has capabilities around camera settings that I cannot easily setup.

code: https://gist.github.com/jlmcmchl/676c4a4b86b9e2dec164a3930b2b46bf

Describe the solution you'd like
PhotonVision adds a block on the cameras page for focus, with the following controls:

  • export siemens star pdf <-- pattern common to lens focusing
    • should we actually do this or should we encourage users to focus on a field
  • choose region of interest <-- tbd how to do this
  • run focus pipeline <-- run some derivative of the above code

Describe alternatives you've considered
This could probably be its own page, I just happen to use it immediately before running camera calibration.

tenengrad metric may not be the best metric to use for image sharpness, I chose something I've seen used elsewhere and haven't reviewed other options.

I have not tested the effects of calibrating at shorter distances vs testing at longer distances (ie - calibrate focus in pit vs detect tags on the field), but it would appear that the ideal strategy would be to configure focus at the same distance you would like to have the best tag detection from.

Design Details

Settings relevant to measuring focus metrics:

  • Region of Interest
    • 4-dimensional (size in x and y, center point in x and y) region of the camera feed evaluated via focus metric
    • 40-60% seems like an appropriate default
  • Sampling History duration
    • How long to remember a focus measurement before it is discarded
    • 6 seconds seems fine
  • Draw Graph
    • whether or not the graph should be drawn on the processed frame
    • unnecessary?
  • Chosen focus metric
    • long term potential: Support selecting other focus metrics in the linked paper or elsewhere

Additional context

Future work - try other focus metrics to see what's best?

A survey paper of focus metrics

Associated matlab implementation

@jlmcmchl jlmcmchl added the enhancement New feature or request label Nov 20, 2024
@Juniormunk
Copy link
Contributor

It looks like Laplacian also works to measure focus. Not sure what fps we are looking at for this code but I guess Laplacian is supposed to be faster.

@jlmcmchl
Copy link
Contributor Author

Your guess was correct, at least on my desktop. The tenengrad metric hits ~40fps, whereas the laplacian hits 55fps. Gist is updated with the modified laplacian from the paper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants