How to set the 32bit-float-disparity format to the pixel format type of the photo.depthData?.depthDataMap property

I'm coding using photo.depthData?.depthDataMap property with iPhoneX(iOS11.4.1). The pixel format of depthDataMap is now "kCVPixelFormatType_DisparityFloat16". I do not explicitly set that format.

Is "kCVPixelFormatType_DisparityFloat16" a default format?

And, How do I set the other format (for example, "kCVPixelFormatType_DisparityFloat32") to the pixel format type of the depthDataMap?

Replies

Photos store depth data in a compressed format (either JPEG or HEVC depending on the container), but yes, kCVPixelFormatType_DisparityFloat16 is the "native" or best format for the depth because it compresses best. We always store the depth map in this format as it's the most space efficient. It's easy, though, to get the depth map data in any format you'd like. Just call AVDepthData's depthDataByConvertingToDepthDataType: method to get a new AVDepthData instance in the format you'd like to work with.

Thank you for replying to my question.

I could not find out AVDepthData's depthDataByConvertingToDepthDataType method. Instead, I found AVDepthData's converting method.

I tried like following.


photo.depthData?.converting(toDepthDataType: kCVPixelFormatType_DisparityFloat32)


But the resulted pixel format was kCVPixelFormatType_DisparityFloat16 by confirming using CVPixelBufferGetPixelFormatType method.

I made a coding mistake. I got a kCVPixelFormatType_DisparityFloat32 pixel format.

Thank you.