Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshot with docker #609

Closed
hhoangg opened this issue Mar 3, 2022 · 4 comments
Closed

Screenshot with docker #609

hhoangg opened this issue Mar 3, 2022 · 4 comments

Comments

@hhoangg
Copy link

hhoangg commented Mar 3, 2022

I deploy source with docker, server Linux, have not GPU
Like the title, I want to use a screenshot function to render the mesh texture layer, but not working
is there any way to export images without GPU?
this my source

from vedo import Mesh, settings, show

settings.screenshotTransparentBackground = True
mesh = Mesh("test.obj").texture("test-design.png").forceOpaque()

x0,x1 = mesh.xbounds()
y0,y1 = mesh.ybounds()
size = ((x1-x0)*5, (y1-y0)*5)

plt = show(mesh, size=size, zoom='tight', interactive=False)

plt.screenshot("result.png")

Linked issue

@antmatyjajo
Copy link
Collaborator

antmatyjajo commented Mar 3, 2022

Hi,

It's quite possible, I am using vedo in this way.

You need to set everything up for offscreen rendering: there are two main ingredients

  1. Vedo should be set to render in offscreen mode
  2. Guest OS in the docker container needs the relevant libraries installed (e.g., see here and here. Specifically in this example we need the Mesa openGL and GLX extensions, and Xvfb to act as a virtual screen.

(I think it's maybe also possible to use OSMesa offscreen driver directly, but that requires a custom build of VTK as far as I know...)

Here is what I am using (NB I am not a docker expert so this is not necessarily optimal or anything...)

  1. Dockerfile
FROM python:3.8-slim-bullseye

RUN apt-get update -y \
  && apt-get install libgl1-mesa-dev libgl1-mesa-glx xvfb -y --no-install-recommends \
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  && rm -rf /var/lib/apt/lists/*

RUN pip install vedo \
  && rm -rf $(pip cache dir)

RUN mkdir -p /app/data

WORKDIR /app/
COPY test.py set_xvfb.sh /app/
ENTRYPOINT ["/app/set_xvfb.sh"]
  1. set_xvfb.sh
#!/bin/bash
set -x
export DISPLAY=:99.0
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
#sleep 3
set +x
exec "$@"
  1. test.py
from vedo import Sphere, Plotter, settings

settings.screenshotTransparentBackground = True

vp = Plotter(interactive=False, offscreen=True)

s = Sphere(pos=[-5, 0, 0], c="r")
vp.show(s)

vp.screenshot("./data/out.png", scale=2)

Then you can

  1. $ docker build -t vedo-test-local .
  2. $ docker run --rm -v /some/path/output:/app/data vedo-test-local python test.py (directory /some/path/output needs to exist)
  3. There should be an "out.png" in the output directory.

Probably a good idea to set specific versions for your packages etc. in the dockerfile to avoid surprises later if vedo API changes or something.

@marcomusy marcomusy pinned this issue Mar 3, 2022
@hhoangg
Copy link
Author

hhoangg commented Mar 4, 2022

@antmatyjajo thanks for the help, but server RAM is not auto-clear when the screenshot function done

@antmatyjajo
Copy link
Collaborator

Sure, no problem.
About the RAM, I don't understand what you mean. docker run --rm ... should both stop and then delete the container once the function has finished running, is that not happening?

@hhoangg
Copy link
Author

hhoangg commented Mar 10, 2022

Sure, no problem. About the RAM, I don't understand what you mean. docker run --rm ... should both stop and then delete the container once the function has finished running, is that not happening?

thank you for your help, I did it, thank you very much, if there is any other problem I will create a new issue :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants