如何将ARKit深度数据(CVPixelBuffer)转换为16位灰度PNG图像文件?
根据Apple官方示例,我做了一些尝试。这是我的代码:
//ARSessionDelegate
func session(_ session: ARSession, didUpdate frame: ARFrame) {
let depthMap = frame.sceneDepth.depthMap
let ciImage = CIImage(cvPixelBuffer: depthMap)
let cgImage = CIContext().createCGImage(ciImage, from: ciImage.extent)
let grayscaleCGImage = cgImage.toGrayscale() //CGImage extension
let image = UIImage(cgImage: grayscaleCGImage)
let data = image.pngData()
//Save data to iPhone as "example.png" PNG file...
//Get "example.png" PNG file from iPhone, copy PNG file to MacOS...
}
然后在 MacOS 终端中,我运行此代码 sips -g all example.png
,我从终端获得以下信息:
pixelWidth: 256
pixelHeight: 192
typeIdentifier: public.png
format: png
formatOptions: default
dpiWidth: 72.000
dpiHeight: 72.000
samplesPerPixel: 1
bitsPerSample: 8
hasAlpha: no
space: Gray
The bitsPerSample
is 8
,但我想要它到为16
。有人可以帮助我吗?多谢!
According to Apple's official example, I made some attempts. This is my codes:
//ARSessionDelegate
func session(_ session: ARSession, didUpdate frame: ARFrame) {
let depthMap = frame.sceneDepth.depthMap
let ciImage = CIImage(cvPixelBuffer: depthMap)
let cgImage = CIContext().createCGImage(ciImage, from: ciImage.extent)
let grayscaleCGImage = cgImage.toGrayscale() //CGImage extension
let image = UIImage(cgImage: grayscaleCGImage)
let data = image.pngData()
//Save data to iPhone as "example.png" PNG file...
//Get "example.png" PNG file from iPhone, copy PNG file to MacOS...
}
Then in MacOS terminal, I run this codes sips -g all example.png
, I get the following information from terminal:
pixelWidth: 256
pixelHeight: 192
typeIdentifier: public.png
format: png
formatOptions: default
dpiWidth: 72.000
dpiHeight: 72.000
samplesPerPixel: 1
bitsPerSample: 8
hasAlpha: no
space: Gray
The bitsPerSample
is 8
, But I want it to be 16
. Can someone help me? Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论