6

in Android Q there is a option to get depth map from image.

Starting in Android Q, cameras can store the depth data for an image in a separate file, using a new schema called Dynamic Depth Format (DDF). Apps can request both the JPG image and its depth metadata, using that information to apply any blur they want in post-processing without modifying the original image data. To read the specification for the new format, see Dynamic Depth Format.

I have read this file Dynamic Depth Format and it looks that depth data is stored in JPG file as XMP metadata and now my question is how to get this depth map from file or directly from android API? I am using galaxy s10 with anrdoid Q

wownis
  • 437
  • 1
  • 5
  • 14
  • hi. Any luck with this ? I am also looking into it and not able to find the depth data – user2991413 Aug 31 '19 at 13:29
  • I did it on google pixel using google camera app. If you take a portrait photo google camera save 2 photos in DCIM folder: first normal and second with blured background, then you need to use exiftool on blured photo with command: exiftool -b -Data file.jpg > depth.jpg and you will recieve depth photo. I still don't know how to get this map programmatically. – wownis Sep 02 '19 at 10:53
  • @wownis did you use a pixel with two rear cameras or only 1? I'm wondering if only 1 rear camera would be able to generate the depth info. And, any luck with your original question? Got the xmp metadata? – Lumi Wang Jan 27 '20 at 10:20
  • @wownis have you found any solution ? – Gomathimeena Subburayan Mar 13 '20 at 13:00

1 Answers1

3

If you retrieve a DYNAMIC_DEPTH jpeg, the depth image is stored in the bytes immediately after the main jpeg image. The documentation leaves a lot to be desired in explaining this; I finally figured it out by searching the whole byte buffer for JPEG start and end markers.

I wrote a parser that you can look at or use here: https://github.com/kmewhort/funar/blob/master/app/src/main/java/com/kmewhort/funar/preprocessors/JpegParser.java. It does the following:

  1. Uses com.drew.imaging.ImageMetadataReader to read the EXIF.
  2. Uses com.adobe.internal.xmp to read info about the depth image sizes (and some other interesting depth attributes that you don't necessarily need, depending on your use case)
  3. Calculates the byte locations of the depth image by subtracting each trailer size from the final byte of the whole byte buffer (there can be other trailer images, such as thumbnails). It returns a wrapped byte buffer of the actual depth JPEG.
Kent Mewhort
  • 1,158
  • 12
  • 11