# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import numpy as np # noqa: E402
import tacto # noqa: E402
from matplotlib import pyplot as plt
# os.environ["PYOPENGL_PLATFORM"] = "osmesa"
# os.environ["PYOPENGL_PLATFORM"] = "EDL"
os.chdir(os.path.dirname(__file__))
# Render from OSMesa should be deterministic
def test_render_from_depth_osmesa():
# tacto.Renderer use np.random.randn to generate noise.
# Fix the random seed here to make test deterministic
np.random.seed(2020)
# Create renderer
renderer = tacto.Renderer(
width=60, height=80, config_path=tacto.get_digit_config_path(), background=None
)
# Get the path of current file
cur_path = os.path.dirname(__file__)
# Render
depthmap = np.load(os.path.join(cur_path, "depthmap.npy"))
color_gt = np.load(os.path.join(cur_path, "color-osmesa-ground-truth.npy"))
color, _ = renderer.render_from_depth(depthmap, scale=0.01)
plt.figure()
plt.subplot(1,3,1)
plt.title("Depth map")
plt.imshow(depthmap)
# plt.colorbar()
plt.subplot(1,3,2)
plt.title("color gt")
plt.imshow(color_gt)
plt.subplot(1,3,3)
plt.title("color sim")
plt.imshow(color)
# NOTE(poweic): This is how ground-truth is generated. Run this in docker
# and make sure you eyeball the resulting image before committing the change
# np.save(os.path.join(cur_path, "color-osmesa-ground-truth.npy"), color)
diff = color - color_gt
rms = (diff ** 2).mean() ** 0.5
print("RMSE:{}".format(rms))
plt.show()
if __name__ == "__main__":
test_render_from_depth_osmesa()
However, the color image doesn't show a contact, which is not consistent with the depth map.
I added matplotlib support to ./tests/test_render_from_depth_osmesa.py to show the generated color images. The modified codes are shown below.
However, the color image doesn't show a contact, which is not consistent with the depth map.
Is it normal?
I really appreciate your reply.