Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift中的卷积滤波器_Ios_Swift_Cifilter - Fatal编程技术网

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类型的属性传递。我想它是自动设置的,但我希望它能帮助找到解决方案。