gpt4 book ai didi

Android Q - 从人像模式照片中获取深度图

转载 作者:行者123 更新时间:2023-12-05 06:22:46 26 4
gpt4 key购买 nike

我正在尝试构建一个示例 Android 应用程序来提取使用谷歌相机应用程序拍摄的人像模式照片的深度图。我知道它是沿着模糊的照片保存的。

我阅读了来自 Google 的动态深度格式文档:https://developer.android.com/training/camera2/Dynamic-depth-v1.0.pdf这是非常新的,我找不到与此主题相关的任何资源或如何管理 android 肖像的深度图的提取。

我使用元数据提取器库以编程方式读取文件的元数据,尤其是 XMP 部分,因为它是描述深度信息的地方。我用 Kotlin 编写了一个示例代码来尝试提取深度图:

val inputStream = contentResolver.openInputStream(imageUri)

inputStream?.let { stream ->
val metadata = JpegMetadataReader.readMetadata(stream)
val directories = metadata.directories
val xmpDirectories = metadata.getDirectoriesOfType(XmpDirectory::class.java)

for (xmpDirectory in xmpDirectories) {
val xmpMeta = xmpDirectory.xmpMeta
val itr = xmpMeta.iterator()

while (itr.hasNext()) {
val propertyInfo = itr.next() as XMPPropertyInfo

println(propertyInfo.path + " :: " + propertyInfo.value)
}
}

stream.close()
}

结果输出:

    xmpNote:HasExtendedXMP :: 5c970bbab778024b23c5a8269325455c
null :: null
GCreations:CameraBurstID :: 9e286063-a919-4a74-96ee-d7e02d2a17d2
null :: null
GCamera:BurstID :: 9e286063-a919-4a74-96ee-d7e02d2a17d2
GCamera:BurstPrimary :: 1
GCamera:SpecialTypeID ::
GCamera:SpecialTypeID[1] :: com.google.android.apps.camera.gallery.specialtype.SpecialType-PORTRAIT
null :: null
Device:Container ::
Device:Container/Container:Directory ::
Device:Container/Container:Directory[1] ::
Device:Container/Container:Directory[1]/Item:Mime :: image/jpeg
Device:Container/Container:Directory[1]/Item:Length :: 0
Device:Container/Container:Directory[1]/Item:DataURI :: primary_image
Device:Container/Container:Directory[1]/rdf:type :: http://ns.google.com/photos/dd/1.0/container/:Item
Device:Container/Container:Directory[2] ::
Device:Container/Container:Directory[2]/Item:Mime :: image/jpeg
Device:Container/Container:Directory[2]/Item:Length :: 1499039
Device:Container/Container:Directory[2]/Item:DataURI :: android/original_image
Device:Container/Container:Directory[2]/rdf:type :: http://ns.google.com/photos/dd/1.0/container/:Item
Device:Container/Container:Directory[3] ::
Device:Container/Container:Directory[3]/Item:Mime :: image/jpeg
Device:Container/Container:Directory[3]/Item:Length :: 316885
Device:Container/Container:Directory[3]/Item:DataURI :: android/depthmap
Device:Container/Container:Directory[3]/rdf:type :: http://ns.google.com/photos/dd/1.0/container/:Item
Device:Container/Container:Directory[4] ::
Device:Container/Container:Directory[4]/Item:Mime :: image/jpeg
Device:Container/Container:Directory[4]/Item:Length :: 65189
Device:Container/Container:Directory[4]/Item:DataURI :: android/confidencemap
Device:Container/Container:Directory[4]/rdf:type :: http://ns.google.com/photos/dd/1.0/container/:Item
Device:Profiles ::
Device:Profiles[1] ::
Device:Profiles[1]/Profile:Type :: DepthPhoto
Device:Profiles[1]/Profile:CameraIndices ::
Device:Profiles[1]/Profile:CameraIndices[1] :: 0
Device:Profiles[1]/rdf:type :: http://ns.google.com/photos/dd/1.0/device/:Profile
Device:Cameras ::
Device:Cameras[1] ::
Device:Cameras[1]/Camera:Trait :: Physical
Device:Cameras[1]/Camera:Image ::
Device:Cameras[1]/Camera:Image/Image:ItemSemantic :: Original
Device:Cameras[1]/Camera:Image/Image:ItemURI :: android/original_image
Device:Cameras[1]/Camera:DepthMap ::
Device:Cameras[1]/Camera:DepthMap/DepthMap:ItemSemantic :: Depth
Device:Cameras[1]/Camera:DepthMap/DepthMap:Format :: RangeInverse
Device:Cameras[1]/Camera:DepthMap/DepthMap:Units :: Diopters
Device:Cameras[1]/Camera:DepthMap/DepthMap:Near :: 0.302570
Device:Cameras[1]/Camera:DepthMap/DepthMap:Far :: 1.754560
Device:Cameras[1]/Camera:DepthMap/DepthMap:DepthURI :: android/depthmap
Device:Cameras[1]/Camera:DepthMap/DepthMap:MeasureType :: OpticalAxis
Device:Cameras[1]/Camera:DepthMap/DepthMap:ConfidenceURI :: android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IAeTE8/AAAAgA8dUT8AAACAPPZSP3YmPL7W11Q/IaQwvx3CVj9TH5m/SrVYP5Xs2b+bsVo/61wNwFe3XD+Mwy3AucZePy0qTsAM4GA/zpBuwJoDYz+4e4fAqjFlPwivl8CPamc/WeKnwJSuaT+pFbjAEv5rP/pIyMBjWW4/SnzYwN3AcD+br+jA4jRzP+vi+MDYtXU/HosEwSFEeD/GpAzBK+B6P26+FMFpin0/F9gcwaUhgD+/8STBqIWBP2cLLcF58YI/DyU1wV1lhD+4Pj3BmuGFP2BYRcF3Zoc/CHJNwUD0iD+wi1XBSIuKP1mlXcHdK4w/Ab9lwVzWjT+p2G3BG4uPP1HydcF8SpE/+gt+wecUkz/REoPBweqUP6Ufh8F6zJY/eSyLwYq6mD9NOY/BZrWaPyFGk8GUvZw/9lKXwZzTnj/KX5vBCvigP55sn8F6K6M/cnmjwYZupT9GhqfB2sGnPxqTq8ErJqo/7p+vwS6crD/CrLPBsCSvP5e5t8GHwLE/a8a7wY1wtD8/07/BtjW3PxPgw8H4ELo/5+zHwWUDvT+7+cvBHQ7AP48G0MFLMsM/YxPUwThxxj84INjBQ8zJPwwt3MHXRM0/4DngwYnc0D+0RuTB+5TUP4hT6MH5b9g/XGDswXNv3D8wbfDBbZXgPwR69ME
Device:Cameras[1]/Camera:ImagingModel ::
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:FocalLengthX :: 3187.589355
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:FocalLengthY :: 3187.589355
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:ImageWidth :: 4032
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:ImageHeight :: 3024
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:PrincipalPointX :: 2000.483154
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:PrincipalPointY :: 1541.417236
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:Skew :: 0.000000
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:PixelAspectRatio :: 1.000000
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:DistortionCount :: 4
Device:Cameras[1]/Camera:ImagingModel/ImagingModel:Distortion :: AACAPwAAAABBQ7w9AAAAAEgGf74AAAAA5SpFPgAAAAA
Device:Cameras[1]/rdf:type :: http://ns.google.com/photos/dd/1.0/device/:Camera

根据 Google 的文档,深度图图像被序列化为 base64 字符串 XMP 属性。但我不知道如何提取它以生成基于此深度数据的新图像。我认为我几乎解决了我的问题,但我错过了一些关于 Adob​​e XMP 标准的确认。

我发现了一个叫做“sidecar Xmp 文件”的东西,也许我试图找到的深度图就在其中。

我上传到https://www.photopea.com上,成功看到深度图嵌入了照片

最佳答案

像素手机人像模式照片由4个JFIF结构拼接https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format .每个 JFIF 结构都是一个 jpeg 图像。

JFIF 结构以标记 0xFFD8 开始,以标记 0xFFD9 结束。因此,我们可以将一个人像模式图像拆分为 4 个 jpeg 文件。

以下 python 代码打印标记位置并将 PXL_20210107_114027740.PORTRAIT.jpg 拆分为,

  1. pxl_out_0.jpg: 显示图像
  2. pxl_out_1.jpg:原图
  3. pxl_out_2.jpg:256级灰度的深度图
  4. pxl_out_3.jpg:填充了 255 的虚拟图像
with open('PXL_20210107_114027740.PORTRAIT.jpg', mode='rb') as infile:
buffer = infile.read()

bufferlen = len(buffer)
pos = 0
pos_d8 = 0
n = 0
i = 0
while i < bufferlen:
if buffer[i] == 0xff:
pos = i
i += 1
if buffer[i] == 0xd8:
print('ffd8: {0}'.format(pos))
pos_d8 = pos
elif buffer[i] == 0xd9:
print('ffd9: {0} len: {1}'.format(pos, pos - pos_d8 + 2))
with open('pxl_out_{0}.jpg'.format(n), mode='wb') as outfile:
n += 1
outfile.write(buffer[pos_d8: pos + 2])
i += 1

关于Android Q - 从人像模式照片中获取深度图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58957619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com