简体   繁体   English

为什么在Camera2 API中以不同的方式实现缩放?

[英]Why is zoom implemented differently in Camera2 API?

In my Android app, I am trying to implement camera zooming using Camera2 API. 在我的Android应用中,我试图使用Camera2 API来实现相机缩放。 There are numerous examples on how to implement zoom using Camera2 API. 关于如何使用Camera2 API实现缩放的示例很多。 One such example is mentioned at Zoom Camera2 Preview using TextureView . 使用TextureView的Zoom Camera2 Preview中提到了这样一个示例。 Here is the essential code snippet: 这是基本的代码片段:

float maxZoom = characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM));
currentZoom = adjustZoom(currentZoom, maxZoom);
Rect m = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
Rect m1 = cropRectangleBasedOnZoom(m1, curZoom);
previewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, m1);
...

This seems to work. 这似乎有效。 However, the old Camera1 API has a simple method to set the zoom value. 但是,旧的Camera1 API具有设置缩放值的简单方法。 Why one has to go through the extra logic of adjusting a region in Camera2 API? 为什么必须要通过额外的逻辑来调整Camera2 API中的区域? Does the Camera2 logic results in better picture quality? Camera2逻辑是否可以带来更好的图像质量?

Also, is there a way to obtain the value of maximum optical zoom? 另外,有没有办法获得最大光学变焦的值? Regards. 问候。

With Camera2, devices can support off-axis zoom, which is more flexible than the old API design. 使用Camera2,设备可以支持离轴缩放,这比旧的API设计更加灵活。 That said, not all devices support that feature, and you can check if a device does via SCALER_CROPPING_TYPE . 也就是说,并非所有设备都支持该功能,您可以通过SCALER_CROPPING_TYPE检查设备是否支持该功能。

And in general, camera2 tries to tie all coordinates to the sensor active array, so it's always clear what part of the sensor is being considered, so it's a matter of consistency. 通常,camera2尝试将所有坐标绑定到传感器活动数组,因此始终很清楚要考虑传感器的哪一部分,因此这是一致性的问题。

Optical zoom isn't supported via the crop region; 裁剪区域不支持光学变焦。 it's strictly about digital zoom. 这完全是关于数码变焦。 If optical zoom is supported by a device, it's via AVAILABLE_FOCAL_LENGTHS and LENS_FOCAL_LENGTH . 如果设备支持光学变焦,则通过AVAILABLE_FOCAL_LENGTHSLENS_FOCAL_LENGTH进行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM