如何解决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 举报,一经查实,本站将立刻删除。