小编Mic*_*her的帖子

如何在 Swift 中从 JPEG 中提取深度

以下代码似乎无法从图像(包含深度信息)中提取深度数据。代码在“guard { auxdepthinfo -...)”行之后返回 nil。在以下代码中,图像是对相册中存储的肖像图像的引用。

struct DepthReader {
    var image: UIImage

    func depthDataMap() -> CVPixelBuffer? {
        //create data from UIImage
        guard let imageDat: Data = UIImageJPEGRepresentation(image, 1.0) else {
            return nil
        }

        //create source
        guard let source = CGImageSourceCreateWithData(imageDat as CFData, nil) else {
            return nil
        }

        //extract auxData disparity data
        guard let auxDataInfo = CGImageSourceCopyAuxiliaryDataInfoAtIndex(source, 0, kCGImageAuxiliaryDataTypeDepth) as? [AnyHashable : Any] else {
            return nil
        }

        // This is the star of the show!
        var depthData: AVDepthData

        do { …
Run Code Online (Sandbox Code Playgroud)

depth ios swift

5
推荐指数
0
解决办法
643
查看次数

标签 统计

depth ×1

ios ×1

swift ×1