Skip to content

Commit d851bc3

Browse files
shapovalovfacebook-github-bot
authored andcommitted
Read depth maps from OpenXR files
Summary: Blender uses OpenEXR to dump depth maps, so we have to support it. OpenCV requires to explicitly accepth the vulnerabilities by setting the env var before exporting. We can set it but I think it should be user’s responsibility. OpenCV error reporting is adequate, so I don’t handle the error on our side. Reviewed By: bottler Differential Revision: D47403884 fbshipit-source-id: 2fcadd1df9d0efa0aea563bcfb2e3180b3c4d1d7
1 parent 8164ac4 commit d851bc3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pytorch3d/implicitron/dataset/utils.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,21 @@ def load_mask(path: str) -> np.ndarray:
245245

246246

247247
def load_depth(path: str, scale_adjustment: float) -> np.ndarray:
248-
if not path.lower().endswith(".png"):
248+
if path.lower().endswith(".exr"):
249+
# NOTE: environment variable OPENCV_IO_ENABLE_OPENEXR must be set to 1
250+
# You will have to accept these vulnerabilities by using OpenEXR:
251+
# https://github.com/opencv/opencv/issues/21326
252+
import cv2
253+
254+
d = cv2.imread(path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)[..., 0]
255+
d[d > 1e9] = 0.0
256+
elif path.lower().endswith(".png"):
257+
d = load_16big_png_depth(path)
258+
else:
249259
raise ValueError('unsupported depth file name "%s"' % path)
250260

251-
d = load_16big_png_depth(path) * scale_adjustment
261+
d = d * scale_adjustment
262+
252263
d[~np.isfinite(d)] = 0.0
253264
return d[None] # fake feature channel
254265

0 commit comments

Comments
 (0)