Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.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
iOS6:如何使用YUV到RGB从cvPixelBufferref到CIImage的转换功能_Ios_Objective C_Ios6_Core Image - Fatal编程技术网

iOS6:如何使用YUV到RGB从cvPixelBufferref到CIImage的转换功能

iOS6:如何使用YUV到RGB从cvPixelBufferref到CIImage的转换功能,ios,objective-c,ios6,core-image,Ios,Objective C,Ios6,Core Image,从iOS6开始,苹果公司已经通过此次通话向CIImage提供了使用本机YUV的条款 initWithCVPixelBuffer:选项: 在核心图像编程指南中,他们提到了此功能 利用iOS 6.0及更高版本中对YUV映像的支持。 相机像素缓冲区本机是YUV,但大多数图像处理 算法需要RBGA数据。在两种模式之间转换是有成本的 两个。Core Image支持从CVPixelBuffer对象和 应用适当的颜色变换 选项=@{(id)kCVPixelBufferPixelFormatTypeKey: @

从iOS6开始,苹果公司已经通过此次通话向CIImage提供了使用本机YUV的条款

initWithCVPixelBuffer:选项:

在核心图像编程指南中,他们提到了此功能

利用iOS 6.0及更高版本中对YUV映像的支持。 相机像素缓冲区本机是YUV,但大多数图像处理 算法需要RBGA数据。在两种模式之间转换是有成本的 两个。Core Image支持从CVPixelBuffer对象和 应用适当的颜色变换

选项=@{(id)kCVPixelBufferPixelFormatTypeKey: @(KCVPIxelFormattType_420YpCvCr88iPlanarFullRange)}

但是,我无法正确使用它。我有一个原始的YUV数据。所以,这就是我所做的

                void *YUV[3] = {data[0], data[1], data[2]};
                size_t planeWidth[3] = {width, width/2, width/2};
                size_t planeHeight[3] = {height, height/2, height/2};
                size_t planeBytesPerRow[3] = {stride, stride/2, stride/2};
                CVPixelBufferRef pixelBuffer = NULL;
                CVReturn ret = CVPixelBufferCreateWithPlanarBytes(kCFAllocatorDefault,
                               width, 
                               height,
                               kCVPixelFormatType_420YpCbCr8PlanarFullRange, 
                               nil,
                               width*height*1.5,
                               3, 
                               YUV,
                               planeWidth,
                               planeHeight, 
                               planeBytesPerRow, 
                               nil,
                               nil, nil, &pixelBuffer); 

    NSDict *opt =  @{ (id)kCVPixelBufferPixelFormatTypeKey :
                        @(kCVPixelFormatType_420YpCbCr8PlanarFullRange) };

CIImage *image = [[CIImage alloc]   initWithCVPixelBuffer:pixelBuffer options:opt];
我的形象得到零分。你知道我错过了什么吗

编辑: 我在通话前添加了锁定和解锁基址。此外,我转储了pixelbuffer的数据,以确保pixelbuffer正确地保存数据。看起来只有init调用有问题。静止图像对象返回零

 CVPixelBufferLockBaseAddress(pixelBuffer, 0);
CIImage *image = [[CIImage alloc]   initWithCVPixelBuffer:pixelBuffer options:opt];
 CVPixelBufferUnlockBaseAddress(pixelBuffer,0);

控制台中应该有错误消息:
initWithCVPixelBuffer失败,因为CVPixelBufferRef未支持IOSurface
。有关如何创建IOSurface-backed
CVPixelBuffer
,请参阅苹果的

调用
CVPixelBufferCreateWithBytes()
CVPixelBufferCreateWithPlanarBytes()
将导致
CVPixelBuffers
不支持IOSurface

…为此,在使用
cvpixelbufferiosurfaceproperties()创建像素缓冲时,必须在
pixelbufferiosurfaceattributes
字典中指定
kCVPixelBufferIOSurfacePropertiesKey

或者,如果提供给
cvpixelbufferiosurfacepropertieskey
pixelbufferiosurfaceattributes
字典包括
kCVPixelBufferIOSurfacePropertiesKey
,则可以使用现有像素缓冲池中的
CVPixelBufferPoolCreatePixelBuffer()


我正在研究一个类似的问题,并不断地从苹果那里找到同样的引语,而没有任何关于如何在YUV颜色空间中工作的进一步信息。我遇到了以下情况:

默认情况下,Core Image假定处理节点是使用GenericRGB颜色空间的每像素128位线性光预乘RGBA浮点值。通过提供Quartz 2D CGColorSpace对象,可以指定不同的工作颜色空间。请注意,工作颜色空间必须基于RGB。如果有YUV数据作为输入(或其他非基于RGB的数据),则可以使用ColorSync函数转换为工作颜色空间。(有关创建和使用CGColorspace对象的信息,请参阅《Quartz 2D编程指南》) 使用8位YUV 4:2:2源,Core Image每GB可以处理240个高清层。八位YUV是DV、MPEG、未压缩D1和JPEG等视频源的本机颜色格式。您需要将核心图像的YUV颜色空间转换为RGB颜色空间


我注意到没有YUV颜色空间,只有灰色和RGB;还有他们的表亲。我还不确定如何转换颜色空间,但如果我发现了,我肯定会在这里报告。

您能解决它吗。如果是,请发布您的解决方案Hi Rugger,如果您能够解决,请提供解决方案。谢谢
NSDictionary *pixelBufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSDictionary dictionary], (id)kCVPixelBufferIOSurfacePropertiesKey,
    nil];
// you may add other keys as appropriate, e.g. kCVPixelBufferPixelFormatTypeKey,     kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, etc.
 
CVPixelBufferRef pixelBuffer;
CVPixelBufferCreate(... (CFDictionaryRef)pixelBufferAttributes,  &pixelBuffer);