GPUImage灰度实时相机输入,带有重叠的动画静态

时间:2015-01-27 21:47:30

标签: ios swift gpuimage

我试图让实时相机显示为灰度,并且动画静态重叠。

我有灰度工作,这很容易,但我也很难搞清楚叠加图像(更不用说动画了)。

任何帮助/让我知道有重叠动画是不值得欣赏? 感谢。

灰度代码:

private var videoCamera: GPUImageVideoCamera?
private var videoView: GPUImageView?
private var greyscaleFilter: GPUImageGrayscaleFilter?

videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset352x288, cameraPosition: .Back)

videoView = GPUImageView(frame: CGRect(x: 0, y: 0, width: 352, height: 288))
view.addSubview(videoView!)

greyscaleFilter = GPUImageGrayscaleFilter()
greyscaleFilter?.addTarget(videoView)

videoCamera?.addTarget(greyscaleFilter);
videoCamera?.startCameraCapture()

编辑:这是我目前所处的位置,我使用GPUImage提供的示例,但无法理解为什么它还没有工作。 (overlay.jpg是我用来测试的图像,认为混合将更明显,而不是我真正需要的微妙静态)。这段代码只生成灰度视频,混合滤镜似乎根本没有做任何事情。

videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset352x288, cameraPosition: .Back)

videoView = GPUImageView(frame: CGRect(x: 0, y: 0, width: 352, height: 288))
view.addSubview(videoView!)

greyscaleFilter = GPUImageGrayscaleFilter()
videoCamera?.addTarget(greyscaleFilter)
greyscaleFilter?.addTarget(videoView)

blendFilter = GPUImageOverlayBlendFilter()
videoCamera?.addTarget(blendFilter)
inputImage = ImageCache.loadImage(named: "overlay.jpg")
blendImage? = GPUImagePicture(image: inputImage)
blendImage?.addTarget(blendFilter)
blendImage?.processImage()
blendFilter?.addTarget(videoView)

videoCamera?.startCameraCapture()

1 个答案:

答案 0 :(得分:0)

最后回到这个,我得到了它的工作,不完全确定为什么它不是以前,但;我将一些类型更改为不可选,因此必须在我的ViewController的init(coder aDecoder:NSCoder)方法中初始化它们,之后这样做很有效。

以下更新的代码。

var videoCamera: GPUImageVideoCamera
var videoView: GPUImageView
var greyscaleFilter: GPUImageGrayscaleFilter
var blendFilter: GPUImageOverlayBlendFilter
var blendImage: GPUImagePicture?
var inputImage: UIImage?

required init(coder aDecoder: NSCoder) {
    videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .Back)
    videoView = GPUImageView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))

    blendFilter = GPUImageOverlayBlendFilter()
    greyscaleFilter = GPUImageGrayscaleFilter()

    super.init(coder: aDecoder)
}

override func viewDidLoad() {
    view.addSubview(videoView)

    videoCamera.addTarget(greyscaleFilter)

    greyscaleFilter.addTarget(blendFilter)

    let inputImage = ImageCache.loadImage(named: "overlay.jpg")
    self.blendImage = GPUImagePicture(image: inputImage)
    self.blendImage?.addTarget(blendFilter)
    self.blendImage?.processImage()
    blendFilter.addTarget(videoView)

    videoCamera.startCameraCapture()

    super.viewDidLoad()
}