I tried many time to set a distance focus on camera2 API, or set autofocus just on a specific area initialized at the start of the activity.
But it still not working...
Could you help me please ? :)
here is my configuration :
captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
captureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
MeteringRectangle[] focusArea = new MeteringRectangle[1];
focusArea[0] = new MeteringRectangle(new Rect(rectangle.getLeft(),rectangle.getTop(),
rectangle.getRight(), rectangle.getBottom()), MeteringRectangle.METERING_WEIGHT_MAX);
captureRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, focusArea);
//captureRequestBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE,10000000000.0f);
You don't include the code where you call either CameraCaptureSession.capture or setRepeatingRequest. But you should not set TRIGGER_START in a repeating request, since that'll restart focus on every frame. Only use it in a single capture() call.
Also, did you mean you change CONTROL_AF_MODE, not CONTROL_MODE? The latter doesn't affect the type of autofocus used, and I'm assuming you want to do AF_MODE_AUTO for a touch-to-focus operation.
If you want manual focus, you'd need to set AF_MODE_OFF to disable autofocus.
Related
If you want to set the focus to a certain value (say, 10f) while building a CameraX camera, it's pretty easy ...
normally ...
previewBuilder = new Preview.Builder();
preview = previewBuilder.build();
launch camera with a fixed focus ...
previewBuilder = new Preview.Builder();
Camera2Interop.Extender x = new Camera2Interop.Extender(previewBuilder);
x.setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF);
x.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, 10f);
preview = previewBuilder.build();
The camera and preview will now run, with the focus fixed at "10f".
But in CameraX how do you actually change the focus to some new value, say 5f
So for example using a slider to control the focus - while the camera is actually running.
I am aware you can tap to focus, but I wanna be able to give it a value, such as "5f".
BTW I tried changing the value, on the extended builder, while the camera is running (by hanging on to the builder), which wouldn't make any sense, but in fact you can't do it anyway, you just get an error.
I investigated FocusMeteringAction and it only allows for tap-to-focus; it does not have a "set the value" function.
Any ideas?
Is it possible to set the camera focus to AF-S or MF using CameraX?
I don't want my camera to focus automaticaly.
I've been making some google search about it, but didn't found anything about this subject yet.
Is it possible to use Camera2 capabilities on CameraX in order to achive this?
After some debug just found how to AF-S instead of AF-C with CameraX.
By default when you set a FocusMeteringAction it has a default cancelation of 5secs, what does it mean?
After you tap for focus or focus in an area for example after 5 secs it will automaticaly cancel your FocusMeteringAction and return to AF-C mode.
In order to AF-S in CameraX the only thing you need to do is to disableAutoCancel() when you are building your FocusMeteringAction.
Make sure that you manually cancel your previous FocusMeteringAction before you create a new one with cancelFocusAndMetering().
Trying to implement tap to focus using camera2api.
CaptureRequest.Builder afBuilder = mPreviewBuilder;
Rect newRect=new Rect(0,0,200,200);
MeteringRectangle meteringRectangle=new MeteringRectangle(newRect,METERING_WEIGHT_DONT_CARE);
MeteringRectangle[] areas = afBuilder.get(CaptureRequest.CONTROL_AF_REGIONS);
mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS,areas);
mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), mCaptureCallback, mBackgroundHandler);
In my call back I am continuously getting stuck in an ACTIVE_SCAN state and occasionally goes into FOCUS_NOT_LOCKED state. I can never seem to get into a FOCUS_LOCKED state and the preview never look focused.
Using a samsung galaxy note 3.
For one, you're not actually setting an AF region - you're just reusing the default region from mPreviewBuilder.
Second, even if you set the region to [(0,0,200,200), METERING_WEIGHT_DONT_CARE], that's the top-left corner of the image, and probably not what you want?
Third, and most importantly, you're setting the AF trigger to be repeating. This means that on every frame, you're asking the camera to restart focusing. So it will never complete, because you never let it.
You need to set AF_TRIGGER to START for only a single capture; you'll still want to set the AF_REGION and AF_MODE on repeating request to be consistent through the whole AF scan you're starting.
According to offical google team statement the CONTROL_AE_EXPOSURE_COMPENSATION manual change is broken on Android 5.1. I'm lookin for a workaround for couple of days and the only one I found is connected to SENSOR_INFO_SENSITIVITY_RANGE. However, I found some difficulties in using it. My code look like this:
if(!modeDisabled){
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
modeDisabled=true;
}
range1 = characteristics.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE);
minmin = range1.getLower();
maxmax = range1.getUpper();
int iso = ((i * (maxmax - minmin)) / 100 + minmin);
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, iso);
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null, mBackgroundHandler);
Of course the 'i' value is a progress value taken from the seekbar and everyting is closed in OnProgressChanged function.
The problem is that there are no visible changes when manipulating the seekbar. I'd be really gratetful for any help.
CONTROL_AE_EXPOSURE_COMPENSATION isn't broken in Android 5.1 in general, it was disabled on the Nexus 6 only (and will be re-enabled in a future update).
If you're disabling auto-exposure, you probably also need to set the exposure time, in addition to the sensitivity. You also preferably need to set the frame duration, though the defaults for both are probably 1/30s, which is reasonable. You can also copy the latest values for those from the most-recent capture result that did you auto-exposure.
That said, you should still see some sort of change here. Is it possible that you're overwriting your capture request elsewhere right after you set this one as the repeating request? You can check the returned capture results to see what the sensitivity setting the camera device is receiving is.
I'm developing an Android application with a camera-related functionality feature.
First of all, I read a lot of stuff on SO, XDA and so on, then please don't redirect me to other useless posts.
I am trying to implement something like a "fixed focus mode", so that:
I start my application with FOCUS_MODE_AUTO (or something else);
bring into focus an object at an arbitrary distance;
fix the current focus;
move the camera on another object at a different distance which is out of focus.
I tried different solutions, i.e.:
mCamera.cancelAutoFocus() in the AutoFocusCallback to prevent the adjustment of the focus;
set a FocusArea: new Camera.Area(new Rect(-50, -50, 50, 50), 1000) to fix the focus on the current area.
I'm targeting API 20 and I'm working on a Samsung Galaxy S5. On this device, the supported focus modes are:
- auto
- infinity
- macro
- continuous-video
- continuous-picture
The suggestion that I found more frequently is to recompile Android...
"AUTO" mode doesn't mean that the camera continuously focuses - just that when you call the autoFocus command the focus is done automatically with no indication on what result you expect not like "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 the autoFocus (as many examples do or call it again in the Callback) your focus should stay after it runs once.
If I understand, you want to focus keep the focus of the first object.
Have you tried to change the camera mode to FOCUS_MODE_FIXED after you focus the first object ?
Like that :
Camera.Parameters mParam = mCamera.getParameters();
mParam.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED);
mCamera.setParameters(mParam);