ImageCapture.Builder setBufferFormat(ImageFormat.YUV_420_888) and setTargetResolution() not working

瀏覽次數:748 次
跳到第一則未讀訊息

Marvin Effing

未讀,
2021年7月5日 清晨7:28:202021/7/5
收件者:Android CameraX Discussion Group
Hi,

I have currently an issue with combining image capture and image resolution. Upon starting the camera, and defining the image capture use case I want to at least:
1. set target resolution of image analysis, e.g. 720x1280
2. set buffer format for image capture which has to be YUV_420_888

This issue occurs for devices whose hardware support level is >= FULL. 

Code is as follows:
```
//picture callback
if (imageCapture == null) {
ImageCapture.Builder builder = new ImageCapture.Builder();

builder.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetResolution(new Size(pictureWidth, pictureHeight))
.setTargetRotation(ROTATION_0);

// if (supportsYUV420()) {
// builder.setBufferFormat(ImageFormat.YUV_420_888);
// }

imageCapture = builder.build();
}

//face detection analysis
if (imageAnalysis == null) {
imageAnalysis = new ImageAnalysis.Builder()
//ensure that backpressure strategy is set to its default strategy for real-time analysis
.setBackpressureStrategy(STRATEGY_KEEP_ONLY_LATEST)
.setTargetResolution(new Size(analysisOutputWidth, analysisOutputHeight))
.setTargetRotation(ROTATION_0)
.build();

setFaceDetector(imageAnalysis, 0.05f);
}
```

The problem is that the attached surface resolution is ALWAYS 480x640 (the DEFAULT size) for image analysis. Now when I remove the line `builder.setBufferFormat(ImageFormat.YUV_420_888);` from image capture initialisation the image analysis' target resolution is as desired. This issue persists over all camx versions. I tried 1.0.0, 1.1.0-alpha04, and 1.1.0-alpha06.

Please assist me in correcting this or is this a bug? 

Marvin Effing

未讀,
2021年7月5日 清晨7:32:152021/7/5
收件者:Android CameraX Discussion Group、Marvin Effing
Function YUV420(): 

private boolean supportsYUV420() {
final CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
final int cameraID = (usingFrontCamera) ? LENS_FACING_FRONT : CameraCharacteristics.LENS_FACING_BACK;

try {
final CameraCharacteristics characteristics = manager.getCameraCharacteristics("" + cameraID);
final int hardwareLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
/* See table defined in
* https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraDevice#createCaptureSession(android.hardware.camera2.params.SessionConfiguration)
* if hardware supported level is either LEGACY (0), LIMITED (1), or EXTERNAL (4), then both target YUV processing isn't supported.
*/
isHardwareSupportFull = hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY &&
hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED &&
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL);
return isHardwareSupportFull;
} catch (CameraAccessException ex) {
Log.e(TAG, "Camera Access Exception retrieving camera characteristics for cameraID: " + cameraID, ex);
ex.printStackTrace();
}

return true;
}

Charcoal Chen

未讀,
2021年7月5日 晚上9:37:362021/7/5
收件者:Marvin Effing、Android CameraX Discussion Group
Hi,

Although a Preview is not mentioned in your code, I guess it should be included in your application. Therefore, your application actually has Preview + ImageCapture + ImageAnalysis use cases combination. It will need PRIV + YUV + YUV configuration when setBufferFormat(ImageFormat.YUV_420_888) is applied to the ImageCapture. Please refer to the "Full-level additional guaranteed configurations" table in the "Regular capture" section of javadoc of CameraDevice. A FULL level above device only supports the following configuration. When the ImageCapture occupies the MAXIMUM size YUV stream, the ImageAnalysis can only occupy the remaining 640x480 YUV stream. That's the reason for the issue you encountered.

YUV640x480PRIVPREVIEWYUVMAXIMUMStandard video recording plus maximum-resolution in-app processing.

When the YUV_420_88 buffer format setting is removed, the following configuration in the "LEGACY-level guaranteed configurations" table will be used. Therefore, the ImageAnalysis can use a PREVIEW size that can be larger than 640x480.

PRIVPREVIEWYUVPREVIEWJPEGMAXIMUMStill capture plus in-app processing.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/5cacf346-1553-4aa9-9915-91d7483a259bn%40android.com.

Marvin Effing

未讀,
2021年7月6日 凌晨1:39:292021/7/6
收件者:Android CameraX Discussion Group、charco...@google.com、Android CameraX Discussion Group、Marvin Effing
I was not aware of this limitation, but that explains the behaviour. Thanks for the information.
回覆所有人
回覆作者
轉寄
0 則新訊息