Set the camera focus to a controlled fixed distance on Android

My device has only two focus modes: AUTO and FIXED (according to getSupportedFocusModes ()). I want to set the camera to a fixed focus distance of "x" (x is what I like, or whatever I can get from the camera). (I know setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED) , but this seems to be fixed only in the most remote setting ..)

Can this be done? (Version 4.2.2 for Android)

+7
android camera
source share
3 answers

Do not try to fully answer this question here, just trying to give it some direction.
So, you need driver support for this kind of operation. Then at some point you ask the driver from your application to set the required focus distance.

Another question: "If someone really needs such functionality?".

Android Documentation:

public static final String FOCUS_MODE_FIXED
Focus is fixed. The camera is always in this mode if the focus is not adjustable. If the camera has autofocus, this mode can lock the focus, which is usually at hyperfocal distance . Applications should not call autoFocus (AutoFocusCallback) in this mode.

Let's see what hyperfocal distance is.

Hyperfocal distance
From Wikipedia, the free encyclopedia

In optics and photography, hyperfocal distance is the distance beyond which all objects can be brought into “acceptable” focus. There are two commonly used definitions of hyperfocal distance, leading to values ​​that differ slightly:

Definition 1: Hyperfocal distance is the closest distance that the lens can be focused, keeping objects at infinity reasonably sharp. When the lens is focused at this distance, all objects at distances from half the hyperfocal distance to infinity will be sharp enough.

Definition 2: hyperfocal distance is the distance beyond which all objects are reasonably sharp, for a lens focused at infinity.

The distinction between the two values ​​is rarely made, since they have almost the same values. The value calculated in accordance with the first definition exceeds the value indicated by the second with just one focal length.

Since hyperfocal distance is the focusing distance giving the maximum depth of field, this is the most desirable distance for setting the focus of a camera with a fixed focus.

Thus, the focus is not set at the most remote setting, but is configured to ensure that all visible objects are sharp enough.

Back to the question.
If you are a developer of this specific camera firmware, you can add all the necessary IOCTLs to it. But then you still have to call them. This cannot be achieved without adding additional features to the Android OS and further recompiling Android itself and the Linux kernel.
It seems you cannot achieve this goal, and not from user space, at least.

+8
source share

One potential approach to achieving this fixed focus distance is to call autofocus at the beginning of the camera's life cycle. Call autofocus periodically until the condition is met. After the condition is satisfied, instead of calling autoFocus, set the flag and call takePicture.

This is one of the solutions I have come up with to get the desired effect that you might be looking for.

So, in my stream that continuously captures images, the code looks something like this:

 if(needsFocus) { myCamera.autoFocus(autoFocusCallback); } else //Focus is not needed anymore at this point { if(myCamera != null) { myCamera.startPreview(); myCamera.takePicture(pictureCallback); } } 

After the condition is met, needsFocus is set to true. At this point, the focus is fixed where I want to. Then this will not change in all other tasks. The condition for my case was the appearance of a certain object found in the OpenCV library.

+1
source share

Maybe I'm wrong, but the way you formulate your question seems to come from the classic perspective of a DSLR lens.

On an Android mobile phone, you don’t actually have to worry about most of the focal length of the lens, unless your mobile camera allows it (which seems not to be the case, as you mention that it just allows you to automatically or fix, rather than infinite, macro , continuous video, etc.).

You can simply set up local areas on the camera to focus and let sdk do its job. If an object touches the image of a camera located far or close to it, sdk works to correctly calculate and focus you.

For example, try this open source project.

0
source share

All Articles