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

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229