Norway


I am trying to read the and overlay it over the UIImageView of a .

So far I have this:

PHImageManager.default().requestImageData(for: self.asset!, options: nil, resultHandler:{ (, responseString, orientation, info) -> Void in
    if let imageData:  =  {
        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_DisparityFloat1 {
                        depthData = depthData.converting(toDepthDataType: kCVPixelFormatType_DisparityFloat1)
                    }
                    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 { }

            }
        }

    }
})

Issues:

  1. Depth map is incorrect and seems to be vague.
  2. Orientation of depth map is incorrect
  3. Depth map color is red for some reason



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here