How to build AVDepthData manually2019 Community Moderator ElectionGet media with AVDepthData without an iPhone 7+How can I develop for iPhone using a Windows development machine?How can I disable the UITableView selection?How to change the name of an iOS app?How do I sort an NSMutableArray with custom objects in it?How to check for an active Internet connection on iOS or macOS?How can I make a UITextField move up when the keyboard is present - on starting to edit?How do I check if a string contains another string in Objective-C?Version vs build in XcodeHow to call Objective-C code from SwiftHow do I get the App version and build number using Swift?

2D counterpart of std::array in C++17

Can elves maintain concentration in a trance?

Humanity loses the vast majority of its technology, information, and population in the year 2122. How long does it take to rebuild itself?

Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

How to explain that I do not want to visit a country due to personal safety concern?

Happy pi day, everyone!

The use of "touch" and "touch on" in context

Rejected in 4th interview round citing insufficient years of experience

Can anyone tell me why this program fails?

Bastion server: use TCP forwarding VS placing private key on server

Fill color and outline color with the same value

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver

Bash replace string at multiple places in a file from command line

Why must traveling waves have the same amplitude to form a standing wave?

Did CPM support custom hardware using device drivers?

Could the Saturn V actually have launched astronauts around Venus?

Why would a flight no longer considered airworthy be redirected like this?

Is it normal that my co-workers at a fitness company criticize my food choices?

Ban on all campaign finance?

Instead of Universal Basic Income, why not Universal Basic NEEDS?

My adviser wants to be the first author

Why are the outputs of printf and std::cout different



How to build AVDepthData manually



2019 Community Moderator ElectionGet media with AVDepthData without an iPhone 7+How can I develop for iPhone using a Windows development machine?How can I disable the UITableView selection?How to change the name of an iOS app?How do I sort an NSMutableArray with custom objects in it?How to check for an active Internet connection on iOS or macOS?How can I make a UITextField move up when the keyboard is present - on starting to edit?How do I check if a string contains another string in Objective-C?Version vs build in XcodeHow to call Objective-C code from SwiftHow do I get the App version and build number using Swift?










0















I want to build my own depth map and save image like portrait photo with depth info. So first of all I need generate AVDepthData. After dig how it builded, I try to reproduce it:



func buildDepth() 
// ...
let info: [AnyHashable: Any] = [kCGImagePropertyPixelFormat: kCVPixelFormatType_DisparityFloat32,
kCGImagePropertyWidth: width,
kCGImagePropertyHeight: height,
kCGImagePropertyBytesPerRow: bytesPerRow]
let metadata = generateMetadata(photo: photo)
let dic: [AnyHashable: Any] = [kCGImageAuxiliaryDataInfoDataDescription: info,
kCGImageAuxiliaryDataInfoData: data,
kCGImageAuxiliaryDataInfoMetadata: metadata]
guard let depthData = try? AVDepthData(fromDictionaryRepresentation: dic) else
return false

print(depthData.cameraCalibrationData) // <----- prints nil


private static func generateMetadata(photo: Photo) -> CGImageMetadata
let metadata = CGImageMetadataCreateMutable()

let fxy = max(photo.orig.size.width, photo.orig.size.height)
let cx = photo.orig.size.width/2
let cy = photo.orig.size.height/2

addMetadataTag(metadata, key: "Filtered", value: true)
addMetadataTag(metadata, key: "Quality", value: "high")
addMetadataTag(metadata, key: "Accuracy", value: "relative")
addMetadataTag(metadata, key: "DepthDataVersion", value: 65538)
addMetadataTag(metadata, key: "PixelSize", value: 0.001000)


addMetadataTag(metadata, key: "LensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])
addMetadataTag(metadata, key: "InverseLensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])


addMetadataTag(metadata, key: "IntrinsicMatrixReferenceWidth", value: photo.orig.size.width)
addMetadataTag(metadata, key: "IntrinsicMatrixReferenceHeight", value: photo.orig.size.height)
addMetadataTag(metadata, key: "LensDistortionCenterOffsetX", value: cx)
addMetadataTag(metadata, key: "LensDistortionCenterOffsetY", value: cy)
addMetadataTag(metadata, key: "ExtrinsicMatrix", value: [1,0,0,
0,1,0,
0,0,1,
0,0,0])

addMetadataTag(metadata, key: "IntrinsicMatrix", value: [fxy,0,0,
0,fxy,0,
cx,cy,1])

addMetadataTag(metadata, type: .depthBlur, key: "SimulatedAperture", value: 4.5)
addMetadataTag(metadata, type: .depthBlur, key: "RenderingParameters", value: "UkVORAEAAAAwAAAAAgAAAJqZmT4K1yM8F0iSOTVeuj0zM7M/DdXOOwAAAD+amRk+")
print(metadata)
return metadata


enum MetadataType
case depth, depthBlur


@discardableResult private static func addMetadataTag(_ metadata: CGMutableImageMetadata, type: MetadataType = .depth, key: String, value: Any) -> Bool
let namespace: String
let prefix: String
switch type
case .depth:
namespace = "http://ns.apple.com/depthData/1.0/"
prefix = "depthData"
case .depthBlur:
namespace = "http://ns.apple.com/depthBlurEffect/1.0/"
prefix = "depthBlurEffect"

guard let metadataTag = CGImageMetadataTagCreate(namespace as CFString, prefix as CFString, key as CFString, .default, value as CFTypeRef)
else return false

print("type", CGImageMetadataTagGetType(metadataTag).rawValue)
return CGImageMetadataSetTagWithPath(metadata, nil, ("xmp:"+key) as CFString, metadataTag)



After this I get AVDepthData witch I can save into image. But this data not contains any additional info like cameraCalibrationData. Dictionary generated by system looks similar to my dictionary.










share|improve this question




























    0















    I want to build my own depth map and save image like portrait photo with depth info. So first of all I need generate AVDepthData. After dig how it builded, I try to reproduce it:



    func buildDepth() 
    // ...
    let info: [AnyHashable: Any] = [kCGImagePropertyPixelFormat: kCVPixelFormatType_DisparityFloat32,
    kCGImagePropertyWidth: width,
    kCGImagePropertyHeight: height,
    kCGImagePropertyBytesPerRow: bytesPerRow]
    let metadata = generateMetadata(photo: photo)
    let dic: [AnyHashable: Any] = [kCGImageAuxiliaryDataInfoDataDescription: info,
    kCGImageAuxiliaryDataInfoData: data,
    kCGImageAuxiliaryDataInfoMetadata: metadata]
    guard let depthData = try? AVDepthData(fromDictionaryRepresentation: dic) else
    return false

    print(depthData.cameraCalibrationData) // <----- prints nil


    private static func generateMetadata(photo: Photo) -> CGImageMetadata
    let metadata = CGImageMetadataCreateMutable()

    let fxy = max(photo.orig.size.width, photo.orig.size.height)
    let cx = photo.orig.size.width/2
    let cy = photo.orig.size.height/2

    addMetadataTag(metadata, key: "Filtered", value: true)
    addMetadataTag(metadata, key: "Quality", value: "high")
    addMetadataTag(metadata, key: "Accuracy", value: "relative")
    addMetadataTag(metadata, key: "DepthDataVersion", value: 65538)
    addMetadataTag(metadata, key: "PixelSize", value: 0.001000)


    addMetadataTag(metadata, key: "LensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])
    addMetadataTag(metadata, key: "InverseLensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])


    addMetadataTag(metadata, key: "IntrinsicMatrixReferenceWidth", value: photo.orig.size.width)
    addMetadataTag(metadata, key: "IntrinsicMatrixReferenceHeight", value: photo.orig.size.height)
    addMetadataTag(metadata, key: "LensDistortionCenterOffsetX", value: cx)
    addMetadataTag(metadata, key: "LensDistortionCenterOffsetY", value: cy)
    addMetadataTag(metadata, key: "ExtrinsicMatrix", value: [1,0,0,
    0,1,0,
    0,0,1,
    0,0,0])

    addMetadataTag(metadata, key: "IntrinsicMatrix", value: [fxy,0,0,
    0,fxy,0,
    cx,cy,1])

    addMetadataTag(metadata, type: .depthBlur, key: "SimulatedAperture", value: 4.5)
    addMetadataTag(metadata, type: .depthBlur, key: "RenderingParameters", value: "UkVORAEAAAAwAAAAAgAAAJqZmT4K1yM8F0iSOTVeuj0zM7M/DdXOOwAAAD+amRk+")
    print(metadata)
    return metadata


    enum MetadataType
    case depth, depthBlur


    @discardableResult private static func addMetadataTag(_ metadata: CGMutableImageMetadata, type: MetadataType = .depth, key: String, value: Any) -> Bool
    let namespace: String
    let prefix: String
    switch type
    case .depth:
    namespace = "http://ns.apple.com/depthData/1.0/"
    prefix = "depthData"
    case .depthBlur:
    namespace = "http://ns.apple.com/depthBlurEffect/1.0/"
    prefix = "depthBlurEffect"

    guard let metadataTag = CGImageMetadataTagCreate(namespace as CFString, prefix as CFString, key as CFString, .default, value as CFTypeRef)
    else return false

    print("type", CGImageMetadataTagGetType(metadataTag).rawValue)
    return CGImageMetadataSetTagWithPath(metadata, nil, ("xmp:"+key) as CFString, metadataTag)



    After this I get AVDepthData witch I can save into image. But this data not contains any additional info like cameraCalibrationData. Dictionary generated by system looks similar to my dictionary.










    share|improve this question


























      0












      0








      0


      1






      I want to build my own depth map and save image like portrait photo with depth info. So first of all I need generate AVDepthData. After dig how it builded, I try to reproduce it:



      func buildDepth() 
      // ...
      let info: [AnyHashable: Any] = [kCGImagePropertyPixelFormat: kCVPixelFormatType_DisparityFloat32,
      kCGImagePropertyWidth: width,
      kCGImagePropertyHeight: height,
      kCGImagePropertyBytesPerRow: bytesPerRow]
      let metadata = generateMetadata(photo: photo)
      let dic: [AnyHashable: Any] = [kCGImageAuxiliaryDataInfoDataDescription: info,
      kCGImageAuxiliaryDataInfoData: data,
      kCGImageAuxiliaryDataInfoMetadata: metadata]
      guard let depthData = try? AVDepthData(fromDictionaryRepresentation: dic) else
      return false

      print(depthData.cameraCalibrationData) // <----- prints nil


      private static func generateMetadata(photo: Photo) -> CGImageMetadata
      let metadata = CGImageMetadataCreateMutable()

      let fxy = max(photo.orig.size.width, photo.orig.size.height)
      let cx = photo.orig.size.width/2
      let cy = photo.orig.size.height/2

      addMetadataTag(metadata, key: "Filtered", value: true)
      addMetadataTag(metadata, key: "Quality", value: "high")
      addMetadataTag(metadata, key: "Accuracy", value: "relative")
      addMetadataTag(metadata, key: "DepthDataVersion", value: 65538)
      addMetadataTag(metadata, key: "PixelSize", value: 0.001000)


      addMetadataTag(metadata, key: "LensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])
      addMetadataTag(metadata, key: "InverseLensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])


      addMetadataTag(metadata, key: "IntrinsicMatrixReferenceWidth", value: photo.orig.size.width)
      addMetadataTag(metadata, key: "IntrinsicMatrixReferenceHeight", value: photo.orig.size.height)
      addMetadataTag(metadata, key: "LensDistortionCenterOffsetX", value: cx)
      addMetadataTag(metadata, key: "LensDistortionCenterOffsetY", value: cy)
      addMetadataTag(metadata, key: "ExtrinsicMatrix", value: [1,0,0,
      0,1,0,
      0,0,1,
      0,0,0])

      addMetadataTag(metadata, key: "IntrinsicMatrix", value: [fxy,0,0,
      0,fxy,0,
      cx,cy,1])

      addMetadataTag(metadata, type: .depthBlur, key: "SimulatedAperture", value: 4.5)
      addMetadataTag(metadata, type: .depthBlur, key: "RenderingParameters", value: "UkVORAEAAAAwAAAAAgAAAJqZmT4K1yM8F0iSOTVeuj0zM7M/DdXOOwAAAD+amRk+")
      print(metadata)
      return metadata


      enum MetadataType
      case depth, depthBlur


      @discardableResult private static func addMetadataTag(_ metadata: CGMutableImageMetadata, type: MetadataType = .depth, key: String, value: Any) -> Bool
      let namespace: String
      let prefix: String
      switch type
      case .depth:
      namespace = "http://ns.apple.com/depthData/1.0/"
      prefix = "depthData"
      case .depthBlur:
      namespace = "http://ns.apple.com/depthBlurEffect/1.0/"
      prefix = "depthBlurEffect"

      guard let metadataTag = CGImageMetadataTagCreate(namespace as CFString, prefix as CFString, key as CFString, .default, value as CFTypeRef)
      else return false

      print("type", CGImageMetadataTagGetType(metadataTag).rawValue)
      return CGImageMetadataSetTagWithPath(metadata, nil, ("xmp:"+key) as CFString, metadataTag)



      After this I get AVDepthData witch I can save into image. But this data not contains any additional info like cameraCalibrationData. Dictionary generated by system looks similar to my dictionary.










      share|improve this question
















      I want to build my own depth map and save image like portrait photo with depth info. So first of all I need generate AVDepthData. After dig how it builded, I try to reproduce it:



      func buildDepth() 
      // ...
      let info: [AnyHashable: Any] = [kCGImagePropertyPixelFormat: kCVPixelFormatType_DisparityFloat32,
      kCGImagePropertyWidth: width,
      kCGImagePropertyHeight: height,
      kCGImagePropertyBytesPerRow: bytesPerRow]
      let metadata = generateMetadata(photo: photo)
      let dic: [AnyHashable: Any] = [kCGImageAuxiliaryDataInfoDataDescription: info,
      kCGImageAuxiliaryDataInfoData: data,
      kCGImageAuxiliaryDataInfoMetadata: metadata]
      guard let depthData = try? AVDepthData(fromDictionaryRepresentation: dic) else
      return false

      print(depthData.cameraCalibrationData) // <----- prints nil


      private static func generateMetadata(photo: Photo) -> CGImageMetadata
      let metadata = CGImageMetadataCreateMutable()

      let fxy = max(photo.orig.size.width, photo.orig.size.height)
      let cx = photo.orig.size.width/2
      let cy = photo.orig.size.height/2

      addMetadataTag(metadata, key: "Filtered", value: true)
      addMetadataTag(metadata, key: "Quality", value: "high")
      addMetadataTag(metadata, key: "Accuracy", value: "relative")
      addMetadataTag(metadata, key: "DepthDataVersion", value: 65538)
      addMetadataTag(metadata, key: "PixelSize", value: 0.001000)


      addMetadataTag(metadata, key: "LensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])
      addMetadataTag(metadata, key: "InverseLensDistortionCoefficients", value: [0,0,0,0,0,0,0,0])


      addMetadataTag(metadata, key: "IntrinsicMatrixReferenceWidth", value: photo.orig.size.width)
      addMetadataTag(metadata, key: "IntrinsicMatrixReferenceHeight", value: photo.orig.size.height)
      addMetadataTag(metadata, key: "LensDistortionCenterOffsetX", value: cx)
      addMetadataTag(metadata, key: "LensDistortionCenterOffsetY", value: cy)
      addMetadataTag(metadata, key: "ExtrinsicMatrix", value: [1,0,0,
      0,1,0,
      0,0,1,
      0,0,0])

      addMetadataTag(metadata, key: "IntrinsicMatrix", value: [fxy,0,0,
      0,fxy,0,
      cx,cy,1])

      addMetadataTag(metadata, type: .depthBlur, key: "SimulatedAperture", value: 4.5)
      addMetadataTag(metadata, type: .depthBlur, key: "RenderingParameters", value: "UkVORAEAAAAwAAAAAgAAAJqZmT4K1yM8F0iSOTVeuj0zM7M/DdXOOwAAAD+amRk+")
      print(metadata)
      return metadata


      enum MetadataType
      case depth, depthBlur


      @discardableResult private static func addMetadataTag(_ metadata: CGMutableImageMetadata, type: MetadataType = .depth, key: String, value: Any) -> Bool
      let namespace: String
      let prefix: String
      switch type
      case .depth:
      namespace = "http://ns.apple.com/depthData/1.0/"
      prefix = "depthData"
      case .depthBlur:
      namespace = "http://ns.apple.com/depthBlurEffect/1.0/"
      prefix = "depthBlurEffect"

      guard let metadataTag = CGImageMetadataTagCreate(namespace as CFString, prefix as CFString, key as CFString, .default, value as CFTypeRef)
      else return false

      print("type", CGImageMetadataTagGetType(metadataTag).rawValue)
      return CGImageMetadataSetTagWithPath(metadata, nil, ("xmp:"+key) as CFString, metadataTag)



      After this I get AVDepthData witch I can save into image. But this data not contains any additional info like cameraCalibrationData. Dictionary generated by system looks similar to my dictionary.







      ios swift avfoundation avdepthdata






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 15:25







      Gralex

















      asked Mar 7 at 12:19









      GralexGralex

      1,65751737




      1,65751737






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043630%2fhow-to-build-avdepthdata-manually%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043630%2fhow-to-build-avdepthdata-manually%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page