简体   繁体   English

CIFilter filterWithCVPixelBuffer在iOS中返回nil

[英]CIFilter filterWithCVPixelBuffer returning nil in iOS

I am trying to create a CIFilter using filterWithCVPixelBuffer and it is returning nil. 我正在尝试使用filterWithCVPixelBuffer创建CIFilter,并且返回nil。 This is what I'm trying to do: 这就是我想要做的:

CFDictionaryRef options = CMCopyDictionaryOfAttachments(nil, photo.pixelBuffer, kCMAttachmentMode_ShouldPropagate);
CIFilter * ciFilter = [CIFilter filterWithCVPixelBuffer:photo.pixelBuffer properties:(__bridge NSDictionary*)options options:nil];

photo is an instance of AVCapturePhoto given to the delegate. photo是提供给委托人的AVCapturePhoto的实例。 I am using iOS 12 and running the code on iPhone7. 我正在使用iOS 12,并在iPhone7上运行代码。

The problem was in the properties NSDictionary. 问题出在属性NSDictionary中。 I should have simply passed photo.metadata. 我应该简单地通过photo.metadata。 So the function call would look like: 因此,函数调用如下所示:

CIFilter * ciFilter = [CIFilter filterWithCVPixelBuffer:photo.pixelBuffer properties:photo.metedata options:nil];

Of course, you can pass an NSDictionary containing the desired CIRAWFilterOption(s) . 当然,您可以传递包含所需CIRAWFilterOption(s)NSDictionary

I think I found the answer in the documentation in the header file: 我在头文件的文档中找到了答案:

Returns a CIFilter that will in turn return a properly processed CIImage as "outputImage". 返回一个CIFilter,该CIFilter随后将返回经过正确处理的CIImage作为“ outputImage”。

Note that when using this initializer, you should pass in a CVPixelBufferRef with one of the following Raw pixel format types kCVPixelFormatType_14Bayer_GRBG, kCVPixelFormatType_14Bayer_RGGB, kCVPixelFormatType_14Bayer_BGGR, kCVPixelFormatType_14Bayer_GBRG as well as the root properties attachment from the CMSampleBufferRef . 注意,使用该初始值设定时,你应该在一个CVPixelBufferRef通过用下面的原始像素格式类型kCVPixelFormatType_14Bayer_GRBG,kCVPixelFormatType_14Bayer_RGGB,kCVPixelFormatType_14Bayer_BGGR,kCVPixelFormatType_14Bayer_GBRG以及从CMSampleBufferRef根属性附件中的一个。

So I guess this method should be used when you have a CMSampleBuffer and is not feasible when coming from a AVCapturePhoto . 因此,我猜想这种方法应该在有CMSampleBuffer情况下使用,而从AVCapturePhoto时不可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM