gpt4 book ai didi

ios - GPUImage2 , 前后摄像头切换

转载 作者:行者123 更新时间:2023-11-28 21:10:04 25 4
gpt4 key购买 nike

如何使用 swift(使用按钮切换)在 GPUImage2(切换版本)中旋转或切换前后摄像头。任何帮助将不胜感激。提前致谢。

最佳答案

让我们考虑 GPUImage2 的主要示例:

do {
camera = try Camera(sessionPreset:AVCaptureSessionPreset640x480)
filter = SaturationAdjustment()
camera --> filter --> renderView
camera.startCapture()
} catch {
fatalError("Could not initialize rendering pipeline: \(error)")
}

一旦你的相机开始拍摄,你可以通过这种方式从后到前切换:

do {

// Stop the capture of the current camera and remove its targets
sharedImageProcessingContext.runOperationSynchronously{
camera.stopCapture()
camera.removeAllTargets()
}

// Build a new Camera object, using the back or front physical camera
if camera.location == .frontFacing {
camera = try Camera(sessionPreset:.vga640x480, location:.backFacing)
} else {
camear = try Camera(sessionPreset:.vga640x480, location:.frontFacing)
}

//Rebuild the pipeline
camera --> filter --> renderView
camera.startCapture()

} catch {
print("Error switching camera : \(error)")
}

旁注#1:使用的默认相机是后置相机,正如 Camera.init() 的默认值所暗示的那样:

public init(sessionPreset:AVCaptureSession.Preset, 
cameraDevice:AVCaptureDevice? = nil,
location:PhysicalCameraLocation = .backFacing,
...

旁注#2:Camera 对象呈现 location 属性。不幸的是,它的 didSet 访问器仍在“TODO”中:

public var location:PhysicalCameraLocation {
didSet {
// TODO: Swap the camera locations, framebuffers as needed
}
}

关于ios - GPUImage2 , 前后摄像头切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43893117/

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