Camera for Android: fixed focus

I am developing an Android application with camera related functionality.

First of all, I read a lot of things about SO, XDA, etc., then please do not redirect me to other useless messages.

I am trying to implement something like "fixed focus mode" so that:

  • I launch my application using FOCUS_MODE_AUTO (or something else);
  • focus an object at an arbitrary distance;
  • lock current focus;
  • move the camera to another object at a different distance that is out of focus.

I tried different solutions, i.e.:

  • mCamera.cancelAutoFocus() in AutoFocusCallback to prevent focus adjustment;
  • set a FocusArea : new Camera.Area(new Rect(-50, -50, 50, 50), 1000) to fix the focus on the current area.

I am targeting API 20 and I am working on a Samsung Galaxy S5. Supported focus modes on this device: - auto - infinity - macro - continuous video - continuous image

The recommendation I found more often is to recompile Android ...

+5
source share
2 answers

The โ€œAUTOโ€ mode does not mean that the camera constantly focuses - just like this, when you call the autoFocus command, the focus is done automatically without indicating what result you expect other than โ€œMacroโ€ or โ€œInfinityโ€.

http://developer.android.com/reference/android/hardware/Camera.html#autoFocus(android.hardware.Camera.AutoFocusCallback)

So, if you don't have a loop that calls autoFocus (as many examples do or call it again in the callback), your focus should remain after it starts.

+2
source

If I understand, you want to focus on the first object. Did you try to change the camera mode to FOCUS_MODE_FIXED after focusing the first object? For instance:

 Camera.Parameters mParam = mCamera.getParameters(); mParam.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED); mCamera.setParameters(mParam); 
-1
source

Source: https://habr.com/ru/post/1211882/


All Articles