Android CameraX 获取当前的展览、焦点等
Posted
技术标签:
【中文标题】Android CameraX 获取当前的展览、焦点等【英文标题】:Android CameraX get current exposition, focus, etc 【发布时间】:2021-06-26 12:58:16 【问题描述】:我想禁用所有自动,这样我可以从相机获得稳定的信号
我尝试在相机启动后 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 并设置当前的博览会,所以它会被手动锁定。但我找不到获取当前博览会的方法,我只能获取 SENSOR_INFO_EXPOSURE_TIME_RANGE
所以,我的问题是
是否可以在运行时获取当前的曝光、焦点、灵敏度等?
【问题讨论】:
【参考方案1】:解决办法是Camera2Interop.setSessionCaptureCallback
onCaptureCompleted
中的参数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)
)
【讨论】:
您使用的是哪个版本?我正在尝试用 java 做,但遇到ExtenderBuilder
的问题
@Balasubramanian 1.1.0-alpha07以上是关于Android CameraX 获取当前的展览、焦点等的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Android CameraX ImageAnalysis 提高帧速率?
如何在android studio中获取camera2 api中的每一帧,例如camera api中的PreviewCallback和camerax中的ImageAnalysis.Analyzer?