I'm using GPUImage
along with CIFilter
to process an image. However, this is proving to be extremely memory intensive, and I'm trying to find a better solution. I'm mainly using CIFilter
, but GPUImage2
provides an AdaptiveThreshold
filter that CIFilter
doesn't supply. As a result, I must use both in my project. Is there a way to transfer the outputImage
of CIFilter
to GPUImage2
without too much overhead? Or is there a way to port a GPUImage2
filter to CIFilter
or vice versa. Here's some example code I'm using now:
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)
Additionally, I'm trying to use CIFilter
in the most efficient way possible by chaining filters like this:
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])