gpt4 book ai didi

ios - videoZoomFactor 不适用于 AVCaptureSession

转载 作者:行者123 更新时间:2023-11-29 10:39:44 32 4
gpt4 key购买 nike

我正在努力解决的缩放问题仍然存在。我尝试按照 link1 中的代码使用 AVCaptureSession 获取图像和 link2 .

一切都很好,除了当我尝试实现相机变焦时,事情不会如我所愿地执行。

我尝试在 AVCaptureDevice 对象上使用 videoZoomFactor 方法,如下面的代码所示。

为什么 videoZoomFactor 没有任何效果,您有什么建议吗??

您将如何按预期使用 AVCaptureSession 为静止图像采集创建缩放??

- (void)addVideoInput {
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice) {

// SOMEHOW NOT HAVING AN EFFECT AT ALL - WHY ?????
if ([videoDevice lockForConfiguration:nil]) {
float zoomFactor = videoDevice.activeFormat.videoZoomFactorUpscaleThreshold;
[videoDevice setVideoZoomFactor:zoomFactor];
// [videoDevice setVideoZoomFactor:3];
// videoDevice.videoZoomFactor = 3;
[videoDevice unlockForConfiguration];
}

// that all works again nicely...
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
if ([[self captureSession] canAddInput:videoIn]) {
[[self captureSession] addInput:videoIn];
}
else
NSLog(@"Couldn't add video input");
}
else
NSLog(@"Couldn't create video input");
}
else
NSLog(@"Couldn't create video capture device");
}

最佳答案

并非所有格式都支持缩放。如果您打印当前格式

NSLog(@"Current format: %@, max zoom factor: %f", videoDevice.activeFormat, videoDevice.activeFormat.videoMaxZoomFactor);

您可能会得到这样的结果(没有缩放级别)。

Current format: <AVCaptureDeviceFormat: 0x1559b3a0 'vide'/'420v' 1280x 720, { 1- 30 fps}, fov:49.240>, max zoom level: 1.000000

那么如果你打印所有格式

NSLog(@"All formats: %@", videoDevice.formats);

你会注意到其中一些有缩放因子,有些没有缩放因子

All formats: (
"<AVCaptureDeviceFormat: 0x1556aef0 'vide'/'420v' 192x 144, { 1- 30 fps}, fov:64.000, binned>",
"<AVCaptureDeviceFormat: 0x1556f4e0 'vide'/'420f' 192x 144, { 1- 30 fps}, fov:64.000, binned>",
"<AVCaptureDeviceFormat: 0x1556f3e0 'vide'/'420v' 352x 288, { 1- 30 fps}, fov:61.260, binned>",
"<AVCaptureDeviceFormat: 0x1556f3f0 'vide'/'420f' 352x 288, { 1- 30 fps}, fov:61.260, binned>",
"<AVCaptureDeviceFormat: 0x1556f360 'vide'/'420v' 480x 360, { 1- 30 fps}, fov:64.000, binned>",
"<AVCaptureDeviceFormat: 0x1556f370 'vide'/'420f' 480x 360, { 1- 30 fps}, fov:64.000, binned>",
"<AVCaptureDeviceFormat: 0x1556ae30 'vide'/'420v' 640x 480, { 1- 30 fps}, fov:64.000, binned>",
"<AVCaptureDeviceFormat: 0x1556ae40 'vide'/'420f' 640x 480, { 1- 30 fps}, fov:64.000, binned>",
"<AVCaptureDeviceFormat: 0x1556f5c0 'vide'/'420v' 960x 540, { 1- 30 fps}, fov:58.460, binned>",
"<AVCaptureDeviceFormat: 0x1556f5d0 'vide'/'420f' 960x 540, { 1- 30 fps}, fov:58.460, binned>",
"<AVCaptureDeviceFormat: 0x1556f3a0 'vide'/'420v' 1280x 720, { 1- 30 fps}, fov:49.240>",
"<AVCaptureDeviceFormat: 0x1556f3b0 'vide'/'420f' 1280x 720, { 1- 30 fps}, fov:49.240>",
"<AVCaptureDeviceFormat: 0x1556aa60 'vide'/'420v' 2592x1936, { 1- 15 fps}, fov:64.000, max zoom:121.00 (upscales @1.00)>",
"<AVCaptureDeviceFormat: 0x1556aa70 'vide'/'420f' 2592x1936, { 1- 15 fps}, fov:64.000, max zoom:121.00 (upscales @1.00)>"

在我的例子中,最后两个具有最大缩放。在这种情况下,我将我的 activeFormat 设置为最后一个(最大缩放大于 1(1 = 无缩放))。你不应该把它当作我的例子(lastObject),你应该首先检查哪种格式的缩放大于1。

videoDevice.activeFormat = [videoDevice.formats lastObject];

现在您可以设置 1.0 和 videoMaxZoomFactor 之间的任意数字。

[videoDevice setVideoZoomFactor:5.0];

关于ios - videoZoomFactor 不适用于 AVCaptureSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125077/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com