我正在使用GPUImage
和CIFilter
来处理图片。然而,这被证明是非常耗费内存的,我正在努力寻找更好的解决方案。我主要使用的是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])