Android CameraX获取当前的展示、焦点等



我想禁用所有自动装置,这样我就可以从相机获得稳定的信号

我试图在相机启动后5秒内锁定AE、AWB、黑色级别的颜色

.setCaptureRequestOption(CaptureRequest.CONTROL_AE_LOCK, true)     
.setCaptureRequestOption(CaptureRequest.BLACK_LEVEL_LOCK, true)                                            
.setCaptureRequestOption(CaptureRequest.CONTROL_AWB_LOCK, true)

它在Pixel 4a上工作,但在启用闪光灯的Galaxy S7上不工作-Galaxy S7不会锁定AE(禁用闪光灯时工作(。我试着设置

setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)

它在S7上工作,但在Pixel 4a上不工作。像素将曝光设置为最小,我看到的几乎是黑色屏幕。

setCaptureRequestOption(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_OFF_KEEP_STATE)

使用相同的

现在我想尝试设置CONTROL_MODE_OFF_KEEP_STATE并设置当前的Exposure,这样它将被手动锁定。但我找不到获取当前EXPOSURE的方法,只能获取SENSOR_INFO_EXPOSURE_TIME_RANGE

所以,我的问题是

是否可以在运行时获得当前曝光、焦点、灵敏度等

解决方案为Camera2Interop.setSessionCaptureCallbackonCaptureCompleted中的参数result: TotalCaptureResult包含所有必需的数据

val builder = ImageAnalysis.Builder();
val camera2InterOp = Camera2Interop.Extender(builder)
camera2InterOp.setSessionCaptureCallback(object : CameraCaptureSession.CaptureCallback() {
override fun onCaptureCompleted(session: CameraCaptureSession, request: CaptureRequest, result: TotalCaptureResult) {
super.onCaptureCompleted(session, request, result)
if (!delayedParamsApplied && System.currentTimeMillis() - startTime > 5000) {
delayedParamsApplied = true
try {
val bundleBuilder =
CaptureRequestOptions.Builder()
.setCaptureRequestOption(CaptureRequest.CONTROL_AE_LOCK, true)
.setCaptureRequestOption(CaptureRequest.BLACK_LEVEL_LOCK, true)
.setCaptureRequestOption(CaptureRequest.CONTROL_AWB_LOCK, true)
getFocusDistance()?.let {
bundleBuilder.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, it)
}
result.get(CaptureResult.SENSOR_EXPOSURE_TIME)?.let {
bundleBuilder.setCaptureRequestOption(CaptureRequest.SENSOR_EXPOSURE_TIME, it)
}
result.get(CaptureResult.SENSOR_SENSITIVITY)?.let {
bundleBuilder.setCaptureRequestOption(CaptureRequest.SENSOR_SENSITIVITY, it)
}
result.get(CaptureResult.SENSOR_FRAME_DURATION)?.let {
bundleBuilder.setCaptureRequestOption(CaptureRequest.SENSOR_FRAME_DURATION, it)
}

bundleBuilder.setCaptureRequestOption(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_OFF_KEEP_STATE)
bundleBuilder.setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)
val bundle = bundleBuilder.build()
cameraControl.captureRequestOptions = bundle
} catch (t: Throwable) {
Timber.e(t)
}
}
}
})

相关内容

  • 没有找到相关文章

最新更新