How to adjust focus on Mavic 3E camera
CompletedHi! I was looking at the documentation on how to adjust the focus on the gimbal camera of the Mavic 3E using the SDK. I would appreciate an example code snippet. When I get close to objects, the drone's camera just looses focus (if i'm closer than 0.5 m) to an object. It would be very helpful for photography. Thanks for your help!
I was so far looking into using this method:
KeyCameraFocusRingValue
but I don't know how to structure the code, i.e. access the drone's camera etc.
-
The KeyCameraFocusRingValue interface is only available in manual focus mode, meaning it may not be possible to achieve automatic focus adjustment through algorithms. I checked the specifications of the Mavic 3E, and the minimum focus distance it supports is 1 meter. Achieving a focus distance of 0.5 meters may not be feasible. -
Yes that's why I want to use manual focus the KeyCameraFocusRingValue interface. My question is how to set up the whole interface programatically in a way that turns manual focus mode on and applies some focus (any random number, I will be experimenting for the optimal one). I would want some example code that uses manual focus and sets a focus value using KeyCameraFocusRingValue. I have a problem with figuring what objects to create and which methods to user. My code does not work right now, nothing happens just a constant zoom that is triggered by
stream.setValue(ZOOM_CAMERA, null, null)
from:
private fun manualFocus(focus: Int) {
KeyCameraFocusMode.apply{ MANUAL }
Log.d("focusing", "manual camera mode is on")
//set video stream to zoom camera
val stream = KeyCameraVideoStreamSource()
stream.setValue(ZOOM_CAMERA, null, null)
//set focus value
KeyCameraFocusRingValue.create(50)
Log.d("focusing", "focus changed")
} -
This is the documentation I am looking at:
-
focusModeKey = KeyTools.createCameraKey(CameraKey.KeyCameraFocusMode,cameraIndex,lensType); KeyManager.getInstance().setValue(focusModeKey, CameraFocusMode.MANUAL, new CommonCallbacks.CompletionCallback() { @Override public void onSuccess() { //result } @Override public void onFailure(@NonNull IDJIError idjiError) { //result } }); The text above is a sample code. Its function is to switch the focus mode to manual mode. You can review the method it uses to create KeyInfo and how to use KeyInfo to control the camera. The usage of KeyCameraFocusRingValue is similar. -
Hi! This is what I have now but the camera does not focus. When I call the function both callbacks succeed. What might be the problem here?
private fun manualFocus(focus: Int) {
var focusModeKey = KeyTools.createCameraKey(
KeyCameraFocusMode,
ComponentIndexType.find(0),
CameraLensType.CAMERA_LENS_ZOOM
)
var setfocusModeKey = KeyTools.createCameraKey(
KeyCameraFocusRingValue,
ComponentIndexType.find(0),
CameraLensType.CAMERA_LENS_ZOOM
)
KeyManager.getInstance().setValue(focusModeKey, MANUAL, object : CommonCallbacks.CompletionCallback {
override fun onSuccess() {
Log.d("Jimmy","MANUAL focus mode is on.")
}
override fun onFailure(error: IDJIError) {
Log.e("Jimmy", "MANUAL focus mode failed.")
}
})
KeyManager.getInstance().setValue(setfocusModeKey, focus, object : CommonCallbacks.CompletionCallback {
override fun onSuccess() {
Log.d("Jimmy","Focus value set success.")
}
override fun onFailure(error: IDJIError) {
Log.e("Jimmy", "Focus value set failure.")
}
})
} -
So i guess the next step would be to adjust focus to some value. i.e. 50. Is this the correct way to do it?
var setfocusModeKey = KeyTools.createCameraKey(
KeyCameraFocusRingValue,
ComponentIndexType.find(0),
CameraLensType.CAMERA_LENS_ZOOM
)KeyManager.getInstance().setValue(setfocusModeKey, 50, object : CommonCallbacks.CompletionCallback {
override fun onSuccess() {
Log.d("Jimmy","Focus value set success.")
}
override fun onFailure(error: IDJIError) {
Log.e("Jimmy", "Focus value set failure.")
}
}) -
If I add the following lines as requested in the documentation https://developer.dji.com/api-reference-v5/android-api/Components/IKeyManager/Key_Camera_CameraKey.html?search=keycamerafocusringval&i=0&#key_camera_camerafocusringvalue_inline, the camera zooms in but focus is not affected / cannot be set afterwards.
val stream = KeyCameraVideoStreamSource()
stream.setValue(ZOOM_CAMERA, null, null) -
Above the KeyCameraFocusRingValue, there are two interfaces: KeyCameraFocusRingMinValue and KeyCameraFocusRingMaxValue. These interfaces are responsible for obtaining the focus ring range supported by KeyCameraFocusRingValue. When adjusting the focus value for a specific lens, you should ensure that the current image source is from that lens. Additionally, you need to wait until the focus mode switches to manual mode before setting the focus ring. You can either add a delay after setting the manual mode or listen for changes in the focus mode. -
Ok so it works perfectly fine. I am setting the exposure (ISO, Shutterspeed), zoom and focus. The only new problem is that the feed coming the default camera after setting all the values mentioned above, changes its dimensions from 1920 x 1080 to something else probably 1280 x 960. I do not change anything, this change is triggered for some reason automatically whenever I change mainly the exposure. Any thoughts? Thanks
Please sign in to leave a comment.
Comments
17 comments