AxisCommunications / acap-native-sdk

ACAP Native SDK
https://hub.docker.com/r/axisecp/acap-native-sdk
Apache License 2.0
13 stars 2 forks source link

Control PTZ and Focus Natively #41

Open whittenator opened 1 year ago

whittenator commented 1 year ago

Describe the feature

This feature(OpticsSDK) would give low-level access to controlling/listening to PTZ(Pan, Tilt, Zoom) and Focus of Cameras. We actively use 4 Axis Q6215-LE to look at objects in the sky and the embedded contrast-based autofocus doesn't do a very good job at focusing on such objects due to low contrast/noise. Thus, we would like to implement our own enhanced auto-focus plugin using the Native SDK. We have attempted to do this but the Native SDK doesn't expose mechanisms to change the focus or listen to the focus. Thus, we opted to use the VAPIX API to do an HTTP call to set the focus and poll the focus. However, we found that setting the focus and polling until the focus changed to the desired focus is too slow to implement a contrast enhanced auto-focus plugin.

pataxis commented 1 year ago

Hi @whittenator , thank you for your feature request!

Today there is no PTZ API in ACAP Native SDK and the one found in ACAP 3 SDK, axptz, will most likely not be migrated.

It's really good to have your use case and I will forward it as input to future APIs.

whittenator commented 1 year ago

Thanks for the info! Does the ACAP3 axptz allow you to control or listen to focus?

pataxis commented 1 year ago

It's handling pan-tilt-zoom operations and in that sense it could control focus by adjusting zoom.

I can mention that in the latest AXIS OS it's possible to call VAPIX from an ACAP application.

I think you posted in another thread that there might be latency problems calling VAPIX, but maybe that was from handling it from a server?

whittenator commented 1 year ago

@pataxis Yeah, we are using the VAPIX API to adjust focus on the Axis Q6215-LE in a Native SDK plugin we developed but we are noticing that it takes ~500-700ms for the focus to settle "close" to the value we are sending it. Our recursive algorithm is similar to this:

  1. void setFocus(int focus)
  2. bool pollForFocusUntilSetteled()
  3. contrastEnhance(cv::Mat Img)
  4. measureSharpness(cv::Mat Img) Repeat until sharpness is at the optimal value.

In step 2, we have timed it multiple times with various sleeps() between polls and it still takes ~500-700ms to settle on the focus value we have set. With such a delay, it makes our autofocus algorithm really slow as we are missing a lot of frames in those 500-700ms. Not sure if this is how long it takes the PTZ camera's focus feedback system to really achieve the value or if the VAPIX is delayed?

It would be fantastic if the images themselves had metadata of the zoom/focus they were captured at. Is there a possibility to enable this?

Thanks