cvPixelBuffer 到 CGImage 转换只给出黑白图像

问题描述

我正在尝试将原始相机传感器数据转换为彩色图像。数据首先在 [UInt16] 数组中提供,然后转换为 cvPixelBuffer。

以下 Swift 5 代码“仅”创建黑白图像并忽略 RGGB 像素数据的滤色器阵列。

我也试过 VTCreateCGImageFromCVPixelBuffer 无济于事。它返回零。

   // imgRawData is a [UInt16] array

   var pixelBuffer: CVPixelBuffer?
   let attrs: [ CFString : Any ]  = [ kCVPixelBufferPixelFormatTypeKey : "rgg4" ]

   CVPixelBufferCreateWithBytes(kcfAllocatorDefault,width,height,kCVPixelFormatType_14Bayer_RGGB,&imgRawData,2*width,nil,attrs as CFDictionary,&pixelBuffer)
   
   // This creates a black-and-white image,not color

   let ciimg = CIImage(cvPixelBuffer: pixelBuffer! )

   let context: CIContext = CIContext.init(options: [ CIContextOption(rawValue: "workingFormat") : CIFormat.RGBA16 ] )
   guard let cgi = context.createCGImage(ciimg,from: ciimg.extent,format: CIFormat.RGBA16,colorSpace: CGColorSpace(name: CGColorSpace.sRGB),deferred: false)
    else { return dummyImg! }


   // This function returns nil
   var cgI: CGImage?
   VTCreateCGImageFromCVPixelBuffer(pixelBuffer!,options: nil,imageOut: &cgI)

非常感谢任何提示

至于去马赛克,我希望 CoreImage 或 CoreGraphics 负责 RGGB 像素颜色插值。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...