我正在使用Swift 3和GPUImage。我有一个名为lut_lookup.png
的LUT图像文件我在静止图像上成功地将其用于GPUImage,它应用并使用LUT过滤器显示结果。
我现在正在尝试将相同的LUT滤镜应用于实时摄像机视图,但我似乎无法让它工作。它基本上甚至不显示相机。
我在下面提供了我的代码,非常感谢任何帮助。这可能是我错过/做错的事情,但我似乎无法发现它。
import UIKit
import GPUImage
class LiveCameraVC: UIViewController
{
// MARK: - Variables
let videoCamera: GPUImageVideoCamera? = {
if let videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .back) {
videoCamera.outputImageOrientation = .portrait
videoCamera.horizontallyMirrorFrontFacingCamera = false
videoCamera.horizontallyMirrorRearFacingCamera = false
return videoCamera
} else {
print("GPUImageVideoCamera Nil")
return nil
}
}()
let filter: GPUImageLookupFilter = {
let filter = GPUImageLookupFilter()
filter.intensity = 1.0
return filter
}()
// MARK: - UI
let modifiedImageView: GPUImageView = {
let imageView = GPUImageView.newAutoLayout()
imageView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
imageView.isUserInteractionEnabled = true
return imageView
}()
// MARK: - Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer().bk_init { [unowned self] (sender:UIGestureRecognizer?, state:UIGestureRecognizerState, location:CGPoint) in
print("Tapped")
self.performLut()
} as! UITapGestureRecognizer
modifiedImageView.addGestureRecognizer(tapGesture)
}
override func loadView() {
super.loadView()
self.view.addSubview(modifiedImageView)
modifiedImageView.autoPinEdgesToSuperviewEdges()
}
// MARK: - Private
private func performLut() {
print("performLut")
if let videoCamera = videoCamera {
if let lookupImageSource = GPUImagePicture(image: UIImage(named:"lut_lookup")) {
videoCamera.addTarget(filter, atTextureLocation: 0)
lookupImageSource.addTarget(filter, atTextureLocation: 1)
filter.addTarget(modifiedImageView)
videoCamera.startCapture()
} else {
print("videoCamera Nil")
}
} else {
print("GPUImageVideoCamera Nil")
}
}
}
由于
答案 0 :(得分:0)
解决了它。我将代码更改为:
let imagePicture: GPUImagePicture? = {
if let imagePicture = GPUImagePicture(image: UIImage(named:"lut_lookup")) {
return imagePicture
} else {
print("GPUImagePicture Nil")
return nil
}
}()
private func performLut() {
if let videoCamera = videoCamera {
if let imagePicture = imagePicture {
videoCamera.addTarget(filter)
imagePicture.addTarget(filter)
imagePicture.processImage()
filter.addTarget(modifiedImageView)
videoCamera.startCapture()
}
}
}
希望能帮助别人!