gpt4 book ai didi

iOS : How to activate image stabilization on an AVCaptureSession?

转载 作者:搜寻专家 更新时间:2023-10-31 22:48:41 32 4
gpt4 key购买 nike

我想在我的应用中捕捉稳定的图像,但我还没有找到实现它所需的配置。

这是我的代码:

let frontCamera = cameraWithPosition(AVCaptureDevicePosition.Front)

let captureSession = AVCaptureSession()

if captureSession.canSetSessionPreset(AVCaptureSessionPresetPhoto) {
captureSession.sessionPreset = AVCaptureSessionPresetPhoto
print("Session preset has been set ")
}
else {
print("Session preset couldn't be set ")
}

var error: NSError?
var input: AVCaptureDeviceInput!
do {
input = try AVCaptureDeviceInput(device: frontCamera)
} catch let error1 as NSError {
error = error1
input = nil
}

if error == nil && captureSession!.canAddInput(input) {
captureSession.addInput(input)
let stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
if stillImageOutput.stillImageStabilizationSupported {
stillImageOutput.automaticallyEnablesStillImageStabilizationWhenAvailable = true
print("Stabilization supported ")
}
else {
print("Stabilization is not supported ")
}
}

因此 session 预设设置正确但不支持图像稳定。

我可以做些什么来支持图像稳定?


** 有节奏的拳头 react 后的第二次尝试: **

我切换到后置摄像头,在设置它之前将输出添加到 captureSession,但我的图像仍然没有稳定:

    let backCamera = cameraWithPosition(AVCaptureDevicePosition.Back)

let captureSession = AVCaptureSession()

if captureSession.canSetSessionPreset(AVCaptureSessionPresetPhoto) {
captureSession.sessionPreset = AVCaptureSessionPresetPhoto
print("Session preset has been set ")
}
else {
print("Session preset couldn't be set ")
}


var error: NSError?
var input: AVCaptureDeviceInput!
do {
input = try AVCaptureDeviceInput(device: backCamera)
} catch let error1 as NSError {
error = error1
input = nil
}

if error == nil && captureSession.canAddInput(input) {
captureSession.addInput(input)
let stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]


if captureSession.canAddOutput(stillImageOutput) {
captureSession.addOutput(stillImageOutput)

if stillImageOutput.stillImageStabilizationSupported == true {
stillImageOutput.automaticallyEnablesStillImageStabilizationWhenAvailable = true
print("Stabilization supported ")
}
else {
print("Stabilization is not supported ")
}

if stillImageOutput.stillImageStabilizationActive == true {
print("Stabilization is active ")
}
else {
print("Stabilization is not active ")
}
}
}

结果是:
不支持稳定
稳定不活跃

最佳答案

首先,您忘记将 AVCaptureStillImageOutput 添加到 AVCaptureSession。您必须在查询其功能之前执行此操作!

captureSession.addOutput(stillImageOutput)

其次,neither Digital nor Optical Image Stabilisation are supported on the front camera .

第三,在后置摄像头上,在支持的平台上(5S以上似乎可以使用数字)AVCaptureStillImageOutput automaticallyEnablesStillImageStabilizationWhenAvailable默认为YES,所以如果切换到后置相机 - 那么您已经使用某种形式的图像稳定。

注意:光学图像稳定 is only available on the 6+ and 6S+ (尽管链接的技术说明尚未针对 6S 型号进行更新)。

关于iOS : How to activate image stabilization on an AVCaptureSession?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32993632/

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