Skip to content

Commit

Permalink
isl-org#17. these changes allow running headless inside the host term…
Browse files Browse the repository at this point in the history
…inal without the need to vnc into the docker container.
  • Loading branch information
takanokage committed Mar 29, 2018
1 parent 8a67fa2 commit 040f5e4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
6 changes: 6 additions & 0 deletions utilities/docker/ubuntu-xvfb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ RUN cmake \
RUN make -j

WORKDIR $HOME

COPY ./setup/.xinitrc .
RUN chmod a+x .xinitrc

COPY ./setup/entrypoint.sh .

WORKDIR $HOME/Open3D/build/lib/Tutorial/Advanced

COPY ./setup/test.py .
RUN chmod a+x test.py

COPY ./setup/test.sh .
RUN chmod a+x test.sh

EXPOSE 5920

CMD ["bash", "/root/entrypoint.sh"]
50 changes: 43 additions & 7 deletions utilities/docker/ubuntu-xvfb/setup/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,54 @@
import faulthandler
faulthandler.enable()

def custom_draw_geometry(pcd):
# The following code achieves the same effect as:
# draw_geometries([pcd])
vis = Visualizer()
def custom_draw_geometry_with_camera_trajectory(pcd):
custom_draw_geometry_with_camera_trajectory.index = -1
custom_draw_geometry_with_camera_trajectory.trajectory =\
read_pinhole_camera_trajectory(
"../../TestData/camera_trajectory.json")
custom_draw_geometry_with_camera_trajectory.vis = Visualizer()
if not os.path.exists("../../TestData/image/"):
os.makedirs("../../TestData/image/")
if not os.path.exists("../../TestData/depth/"):
os.makedirs("../../TestData/depth/")
def move_forward(vis):
# This function is called within the Visualizer::run() loop
# The run loop calls the function, then re-render
# So the sequence in this function is to:
# 1. Capture frame
# 2. index++, check ending criteria
# 3. Set camera
# 4. (Re-render)
ctr = vis.get_view_control()
glb = custom_draw_geometry_with_camera_trajectory
if glb.index >= 0:
print("Capture image {:05d}".format(glb.index))
depth = vis.capture_depth_float_buffer(False)
image = vis.capture_screen_float_buffer(False)
plt.imsave("../../TestData/depth/{:05d}.png".format(glb.index),\
np.asarray(depth), dpi = 1)
plt.imsave("../../TestData/image/{:05d}.png".format(glb.index),\
np.asarray(image), dpi = 1)
#vis.capture_depth_image("depth/{:05d}.png".format(glb.index), False)
#vis.capture_screen_image("image/{:05d}.png".format(glb.index), False)
glb.index = glb.index + 1
if glb.index < len(glb.trajectory.extrinsic):
ctr.convert_from_pinhole_camera_parameters(glb.trajectory.intrinsic,\
glb.trajectory.extrinsic[glb.index])
else:
custom_draw_geometry_with_camera_trajectory.vis.\
register_animation_callback(None)
return False
vis = custom_draw_geometry_with_camera_trajectory.vis
vis.create_window()
vis.add_geometry(pcd)
vis.get_render_option().load_from_json("../../TestData/renderoption.json")
vis.register_animation_callback(move_forward)
vis.run()
vis.destroy_window()

if __name__ == "__main__":
pcd = read_point_cloud("../../TestData/fragment.ply")

print("1. Customized visualization to mimic DrawGeometry")
custom_draw_geometry(pcd)

print("5. Customized visualization playing a camera trajectory")
custom_draw_geometry_with_camera_trajectory(pcd)
5 changes: 5 additions & 0 deletions utilities/docker/ubuntu-xvfb/setup/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Xvfb :99 -screen 0 1920x1080x24 &
DISPLAY=:99.0
export DISPLAY

./test.py

0 comments on commit 040f5e4

Please sign in to comment.