Ios Swift中的卷积滤波器
我的卷积滤波器无法处理我在屏幕上显示的实时视频预览。将过滤器更改为深褐色过滤器显示正确,但将其更改为Ios Swift中的卷积滤波器,ios,swift,cifilter,Ios,Swift,Cifilter,我的卷积滤波器无法处理我在屏幕上显示的实时视频预览。将过滤器更改为深褐色过滤器显示正确,但将其更改为CIConvolution3X3失败 let weights:[CGFloat] = [1, 0, -1, 2, 0, -2, 1, 0, -1] result = (CIFilter(name: "CIConvolution3X3", withInputParameters: [ kCIInputImageKey: result, kCIInputWeightsKey: CIVe
CIConvolution3X3
失败
let weights:[CGFloat] = [1, 0, -1, 2, 0, -2, 1, 0, -1]
result = (CIFilter(name: "CIConvolution3X3", withInputParameters: [
kCIInputImageKey: result,
kCIInputWeightsKey: CIVector(values: weights, count: 9),
kCIInputBiasKey: NSNumber(float: 0.5)
])?.outputImage)!
我也有同样的问题!与上下文稍有不同,我试图将使用
CIConvolution3X3
过滤的结果CIImage
转换为UIImage
。这在运行时失败,并显示与上述相同的症状。(将inputBias
键设置为除0以外的任何值都会导致崩溃)故障的确切行是self.imageView.image=UIImage(ciImage:ciImage)
我确实找到了解决办法。关键是使用CIContext
转换图像:
let context=CIContext(选项:nil)
guard let cgImage=context.createCGImage(ciImage,from:rectangle)else{return}
设uiImage=uiImage(cgImage:cgImage)
希望这能帮助我解决同样的问题。我想问题在于偏倚键,因为没有偏倚它对我有效。你已经弄明白了吗?有没有发现为什么我们不能使用inputBias作为参数?docs()显式指定应将inputBias作为CIAttributeTypedInstance类型的属性传递。我想它是自动设置的,但我希望它能帮助找到解决方案。