我正在尝试添加手动相机控制新的曝光值和ISO值。我正在使用Camera2Basic示例。我现在面临的问题是我是Android新手。我试着看着L-Camera,但它在Scala中让我更加困惑。
我尝试了以下更改,但没有更新图像的预览。
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();
}
}
答案 0 :(得分:3)
首先,您必须将模板更改为TEMPLATE_STILL_CAPTURE
或TEMPLATE_MANUAL
,才能在预览中看到值的变化。另外,请记住将CONTROL_AE_MODE
和'CONTROL_MODE'设置为OFF。
此控件仅在android.control.aeMode或android.control.mode设置为OFF时有效;否则自动曝光算法将覆盖此值。
其次,设置您的值:
builder.set(CaptureRequest.SENSOR_SENSITIVITY, isoValue);
builder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, exposureTimeValueInMilliseconds);
最后,在完成所有更改后,请不要忘记使用CaptureSession.setRepeatingRequest
希望它会对你有所帮助!
答案 1 :(得分:0)
所以我对我的代码进行了以下更改。
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);
然而,我得到了一个奇怪的预览,其中有许多绿灯作为输入。
这是https://postimg.org/image/yl95e6qht/
这就像使用我内置的相机应用程序一样:https://postimg.org/image/lvjnwquj5/
答案 2 :(得分:0)
这将解决问题:
mPreviewBuilder.set(
CaptureRequest.CONTROL_AWB_MODE,
CaptureRequest.CONTROL_AWB_MODE_AUTO
);
答案 3 :(得分:0)
在使用Camera 2 API进行手动曝光时,我也遇到绿色拍摄问题。
我可以通过仅停用CONTROL_AE_MODE
而不是同时CONTROL_AE_MODE
和CONTROL_MODE
来解决此问题。
这是我的配置:
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