I have an application which uses CameraX API with Preview
and Analyzer
Use cases.
I’m setting the desired FPS using the Camera2Interop.Extender()
and setting the CONTROL_AE_TARGET_FPS_RANGE
option to Range(60,60)
for example
val previewBuilder = Preview.Builder()
.setTargetResolution(currentRes)
...
val cameraSelector = CameraSelector.Builder()
.requireLensFacing(cameraLens)
.build()
val fps = ConfigurationService.fps.toInt() // 60
val frameDuration = 1000000000L/fps // 1666666
if (cameraSelector.lensFacing!! == CameraSelector.LENS_FACING_FRONT) {
Camera2Interop.Extender(previewBuilder)
.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
Range(fps, fps))
.setCaptureRequestOption(
CaptureRequest.SENSOR_FRAME_DURATION,
frameDuration
)
}
Then setting up the preview and the analyzer
val preview = previewBuilder.build()
val analysis = ImageAnalysis.Builder()
.setTargetResolution(currentRes)
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.setOutputImageFormat(ConfigurationService.cameraInputType)
.setImageQueueDepth(countOfCores)
.build()
analysis.setAnalyzer(Executors.newWorkStealingPool(Runtime.getRuntime().availableProcessors()), analyzer)
val useCaseGroup = UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(analysis)
.build()
try {
cameraProvider?.unbindAll()
camera = cameraProvider?.bindToLifecycle(
context as LifecycleOwner,
cameraSelector,
useCaseGroup
)
previewView.implementationMode = PreviewView.ImplementationMode.PERFORMANCE
preview.setSurfaceProvider(
previewView.surfaceProvider
)
} catch (e: Exception) {
Log.e("CameraClassificationWrapper", "Use case binding failed", e)
}
The issue I’m facing is that when the FPS is set to anything higher than 30, the incoming images are still of the correct width/height (1280×720) in this case, but it seems to be cropped from part of the sensor, causing the image to appear “zoomed in”. For less than 30 the images seems to be correct.
Since I’m using the analyzer to do real-world measurements using calibrated camera for specific resolutions, I need the images to match what I calibrated with.
I saw several mentions of such issue for other platforms or just for general use case.
I know Camera2
has the CameraConstrainedHighSpeedCaptureSession
way, and I would have used it except that the entire application already uses CameraX
and I would really like to avoid replacing the entire camera backend
Is there anyway of getting full resolution (up to 1080p) in 60 FPS using CameraX?