将GPUImage2与CIFilters一起使用

时间:2017-01-08 05:17:37

标签: ios swift memory gpuimage cifilter

我正在使用GPUImageCIFilter来处理图片。然而,这被证明是非常耗费内存的,我正在努力寻找更好的解决方案。我主要使用的是CIFilter,但GPUImage2提供了AdaptiveThreshold无法提供的CIFilter过滤器。因此,我必须在我的项目中使用这两者。有没有办法将outputImage CIFilter转移到GPUImage2而没有太多开销?或者有没有办法将GPUImage2过滤器移植到CIFilter,反之亦然。这是我现在使用的一些示例代码:

    let openGLContext = EAGLContext(api: .openGLES2)
    let context = CIContext(eaglContext: openGLContext!)

    guard let cgFilteredImage = context.createCGImage(noiseReductionOutput, from: noiseReductionOutput.extent) else {
        completionHandler(nil)
        return
    }

    let correctlyRotatedImage = UIImage(cgImage: cgFilteredImage, scale: imageToProcess.scale, orientation: imageToProcess.imageOrientation)

    //
    // GPUImage
    //

    let orientation = ImageOrientation.orientation(for: correctlyRotatedImage.imageOrientation)

    let pictureInput = PictureInput(image: correctlyRotatedImage, orientation: orientation)
    let processedImage = PictureOutput()

    pictureInput --> adaptiveThreshold --> processedImage

    processedImage.imageAvailableCallback = {
        image in
        completionHandler(image)
    }

    pictureInput.processImage(synchronously: true)

此外,我正在尝试通过链接这样的过滤器以最有效的方式使用CIFilter

    let filter = CIFilter(name: "Filter_Name_Here")!
    guard let filterOutput = filter.outputImage else {
        completionHandler(nil)
        return
    }

    let secondFilter = CIFilter(name: "Filter_Name_Here")!
    secondFilter.setValuesForKeys([kCIInputImageKey: filterOutput])

0 个答案:

没有答案