2

I'm creating an android app that allow user to scan the code on a small card (like yu gi oh card). The problem is that the number I want to read is really small and it's hard to get a good focus to make it clear. So I wanted to set the params to get the best result at closest distance.

At first, I follow this tutorial to create a simple camera preview: https://inducesmile.com/android/android-camera2-api-example-tutorial/

Next I tried to change the camera preview settings to disable auto-focus, it works well, but then I tried to manually set the focus distance, and nothing change.

This is an extract of the code in the camera preview creation methods :

CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
//Disable auto-focus
captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF);
//Try to make it at the shortest distance (do not work)
captureRequestBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, characteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE)

I've tried different parameters on the focus distance, but nothing change. Maybe I'm just making a mistake, and it's not the right way to improve this.

1 Answers1

1

Manual focus control is not a guaranteed feature. Many lower-end devices do not support it, and only support autofocus. You can check if the device has the capability MANUAL_SENSOR. Some cameras are entirely fixed-focus (mostly these are selfie cameras), so those you can't even autofocus.

For your use case, autofocus should work well enough anyway, as long as the small card fills up most of the visible scene.

Note that many devices have a minimum focus distance of 8-10 cm, so you can't hold the card really close and expect to get sharp images of it.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47