Отображение карты глубины из PHAsset - PullRequest
0 голосов
/ 26 сентября 2018

Я пытаюсь прочитать карту глубины и наложить ее на UIImageView PHAsset.

Пока у меня есть это:

PHImageManager.default().requestImageData(for: self.asset!, options: nil, resultHandler:{ (data, responseString, orientation, info) -> Void in
    if let imageData: Data = data {
        if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil) {

            let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary

            let auxDataType = kCGImageAuxiliaryDataTypeDisparity
            let auxDataInfo = CGImageSourceCopyAuxiliaryDataInfoAtIndex(imageSource, 0, auxDataType)
            if auxDataInfo == nil {
                print ("NO DEPTH")
            } else {
                do {
                    var depthData = try AVDepthData(fromDictionaryRepresentation: auxDataInfo as! [AnyHashable : Any])
                    if depthData.depthDataType != kCVPixelFormatType_DisparityFloat16 {
                        depthData = depthData.converting(toDepthDataType: kCVPixelFormatType_DisparityFloat16)
                    }
                    let depthMap : CVPixelBuffer = depthData.depthDataMap
                    var ciImage = CIImage(cvPixelBuffer: depthMap)
                    ciImage = ciImage.applyingFilter("CIDisparityToDepth", parameters: [:])
                    DispatchQueue.main.async {
                        self.imageView.image = UIImage(ciImage: ciImage)
                    }
                }
                catch { }

            }
        }

    }
})

Проблемы:

  1. Карта глубины неверна и кажется расплывчатой.
  2. Неверная ориентация карты глубины
  3. По какой-то причине цвет карты глубины красный
...