Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get depth map in Android Q

Tags:

android

image

api

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

like image 842
wownis Avatar asked Aug 14 '19 12:08

wownis


1 Answers

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.
like image 196
Kent Mewhort Avatar answered Oct 31 '22 16:10

Kent Mewhort