Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CameraX equivalent of Camera2's CaptureRequest

I want to use ImageAnalysis with CameraX, but adjust some Camera settings such as auto-focus or auto-white balance, exposure and frame duration.

Here's an example of the settings I need and how I set them with Camera2:

    captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_OFF)
    captureRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF)
    captureRequestBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION, FRAME_DURATION_NS)
    captureRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, EXPOSURE_TIME_LIMIT_NS)

How can I "translate" this to CameraX?

like image 215
Sharp Avatar asked Mar 03 '20 13:03

Sharp


People also ask

Should I use CameraX?

For new apps, we recommend starting with CameraX. It provides a consistent, easy-to-use API that works across the vast majority of Android devices, with backward-compatibility to Android 5.0 (API level 21).

Is CameraX still in beta?

As part of Android Jetpack, the CameraX library makes complex camera functionality available in an easy-to-use API, helping you create a best-in-class experience that works consistently across Android versions and devices.

What is CameraX Android?

CameraX is an addition to Jetpack that makes it easier to add camera capabilities to your app. The library provides a number of compatibility fixes and workarounds to help make the developer experience consistent across many devices.


1 Answers

There is Camera2InterOp for customizing CaptureRequest parameters. Example:

fun buildImageAnalysis() : ImageAnalysis {
    val builder = ImageAnalysis.Builder()
    val camera2InterOp = Camera2Interop.Extender(builder)
    camera2InterOp.setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_OFF)
    camera2InterOp.setCaptureRequestOption(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF)
    camera2InterOp.setCaptureRequestOption(CaptureRequest.SENSOR_FRAME_DURATION, FRAME_DURATION_NS);
    camera2InterOp.setCaptureRequestOption(CaptureRequest.SENSOR_EXPOSURE_TIME, EXPOSURE_TIME_LIMIT_NS)
    return builder.build()
}
like image 75
Xi 张熹 Avatar answered Sep 30 '22 03:09

Xi 张熹