【发布时间】:2026-01-13 03:20:04
【问题描述】:
我有一个使用AVFoundation 设置相机的启动项目,它运行良好。现在我需要将相机机制转换为GPUImage。我在两个项目中都使用了相同的焦点和曝光方法(在 AVFoundation 项目中效果很好),但在 GPUImage 项目中它不能正确聚焦并且总是错误的。
不要介意应用过滤器,它们都是一样的
示例: 在屏幕的右上角,您可以看到小羊。这就是它获得焦点+曝光的方式。
设置 GPU:
stillCamera = GPUImageStillCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .Front)
CorrectPosition = AVCaptureDevicePosition.Front
stillCamera!.outputImageOrientation = .Portrait;
stillCamera?.horizontallyMirrorFrontFacingCamera = true
filter = GPUImageFilter()
stillCamera?.addTarget(filter)
filter?.addTarget(self.view as! GPUImageView)
(self.view as! GPUImageView).fillMode = GPUImageFillModeType.init(2)
TouchBegan 方法:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
var tap : CGPoint!
if let touch = touches.first as UITouch! {
tap = touch.locationInView(self.view)
}
let device: AVCaptureDevice! = self.stillCamera?.inputCamera!
var error: NSError? = nil
do {
try device.lockForConfiguration()
if device.focusPointOfInterestSupported && device.isFocusModeSupported(AVCaptureFocusMode.AutoFocus){
device.focusMode = AVCaptureFocusMode.AutoFocus
device.focusPointOfInterest = tap
}
if device.exposurePointOfInterestSupported && device.isExposureModeSupported(AVCaptureExposureMode.AutoExpose){
device.exposurePointOfInterest = tap
device.exposureMode = AVCaptureExposureMode.AutoExpose
}
device.subjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange
device.unlockForConfiguration()
} catch let error1 as NSError {
error = error1
print(error)
} catch {
fatalError()
}
}
有什么想法吗?
【问题讨论】:
标签: ios focus gpuimage avcapturedevice gpuimagestillcamera