Reputation: 171
I am trying to add in Manual Camera Controls new exposure value and ISO values. I am using the Camera2Basic Example. The problem I face now is that I am new to Android. I tried looking at L-Camera but its in Scala and that confuses me further.
I tried the following changes but there was no update to the preview of the image.
private void createCameraPreviewSession() {
try {
SurfaceTexture texture = mTextureView.getSurfaceTexture();
assert texture != null;
// We configure the size of default buffer to be the size of camera preview we want.
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
// This is the output Surface we need to start preview.
Surface surface = new Surface(texture);
// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder
= mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
// Here, we create a CameraCaptureSession for camera preview.
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == mCameraDevice) {
return;
}
// When the session is ready, we start displaying the preview.
mCaptureSession = cameraCaptureSession;
try {
// Auto focus should be continuous for camera preview.
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME,Long.valueOf("100000"));
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY,1600);
// Flash is automatically enabled when necessary.
setAutoFlash(mPreviewRequestBuilder);
// Finally, we start displaying the camera preview.
mPreviewRequest = mPreviewRequestBuilder.build();
mCaptureSession.setRepeatingRequest(mPreviewRequest,
mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(
@NonNull CameraCaptureSession cameraCaptureSession) {
showToast("Failed");
}
}, null
);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
Upvotes: 3
Views: 8356
Reputation: 1
I also had problems with green captures when using manual exposure with camera 2 API.
I could fix it by only deactivating CONTROL_AE_MODE
instead of both CONTROL_AE_MODE
and CONTROL_MODE
.
This is my configuration:
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraCharacteristics.CONTROL_AE_MODE_OFF);
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraCharacteristics.CONTROL_MODE_AUTO);
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, Long.valueOf("8000000")); // 8000000 ns = 8 ms
Upvotes: 0
Reputation: 1
This will fix the problem:
mPreviewBuilder.set(
CaptureRequest.CONTROL_AWB_MODE,
CaptureRequest.CONTROL_AWB_MODE_AUTO
);
Upvotes: 0
Reputation: 171
So I have made the following changes to my code.
mPreviewRequestBuilder
= mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL);
mPreviewRequestBuilder.addTarget(surface);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE,
CaptureRequest.CONTROL_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME,Long.valueOf("22000"));
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY,200);
mCaptureSession.setRepeatingRequest(mPreviewRequest,
mCaptureCallback, mBackgroundHandler);
However I get a weird preview with a lot of green light taken as an input.
Here it is https://postimg.org/image/yl95e6qht/
This is what it looks like using my inbuilt camera app: https://postimg.org/image/lvjnwquj5/
Upvotes: 0
Reputation: 13357
First, you must change your template to TEMPLATE_STILL_CAPTURE
or TEMPLATE_MANUAL
to see the values change in the preview. Also, remember to set your CONTROL_AE_MODE
and 'CONTROL_MODE' to OFF.
This control is only effective if android.control.aeMode or android.control.mode is set to OFF; otherwise the auto-exposure algorithm will override this value.
From Android Developer
Second, set your values with:
builder.set(CaptureRequest.SENSOR_SENSITIVITY, isoValue);
builder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, exposureTimeValueInMilliseconds);
Finally after all the changes don't forget to update your preview using a CaptureSession.setRepeatingRequest
Hope it will help you!
Upvotes: 5