Home › Forum › SOFA › Programming with SOFA › Recording images of scenes
- This topic has 30 replies, 12 voices, and was last updated 3 years, 8 months ago by Arthur.
-
AuthorPosts
-
5 February 2021 at 08:10 #18510psomersBlocked
Hi Sofa team,
I saw that the python3 bindings for implementing the pygame example mentioned in this thread were removed shortly after the conversation here took place (glewinit() and draw()). Is there a plan to re-implement them or replace them? Or maybe I’m missing the replacement. Since Sofa can be driven entirely from a python environment, it is pretty handy to be able to implement a simplified viewer without handing over the main thread. I’ve added back in the bindings in my copy of sofa and it’s pretty easy to have a nice gui using pyqt and python debugging capabilities aren’t lost.
I guess I’m asking more out of curiosity than need at the moment.
Keep up the good work!
Cheers,
Peter
5 February 2021 at 10:16 #18520jnbrunetModeratorHey Peter,
I just answer a similar question here: https://www.sofa-framework.org/community/forum/topic/sofapython3-pygame-rendering-example-not-working/#post-18513
Let me know there if you have any further questions.
J-N
9 April 2021 at 17:42 #19121etagliabueBlockedHello everyone,
I am also looking for a way to add a virtual RGB-D sensor in my simulation (thus, both 2D image and depth, giving the whole visible 3D point cloud) and I have come into this thread. Since last post is of some months ago, I am wondering if any of you has made any progress meanwhile and/or has any suggestion? @jieying @balazs @jangirrishabh @pierreshg
Thanks!
Eleonora9 April 2021 at 17:49 #19122psomersBlockedHi Eleonora,
I think this is what you could be looking for. I use it to do exactly what you‘re describing.
Cheers,
Peter9 April 2021 at 18:01 #19124etagliabueBlocked16 April 2021 at 23:02 #19203ArthurBlockedA solution for recording a scene without using SofaPython3. In fact it is a different process entirely that fakes inputs to the gui
If you are running sofa on a linux desktop you can record a running sofa scene with the following python script (N.B. you might have add the –start flag to the runSofa command).
import os import pyautogui import time ##This is needed if you want to record on a desktop with more than one window to make the sofa # gui the active window os.system("wmctrl -l > /tmp/window_list.txt") sofa_window = None with open("/tmp/window_list.txt", "r") as ping: line = ping.readline() while line: if "Sofa -" in line: print(line) i = line.index("Sofa -") sofa_window = line[i:-1] line = ping.readline() cmd_string = 'wmctrl -a "'+sofa_window+ '" ' print(cmd_string) os.system(cmd_string) # this will begin recording wait ten wall clock seconds (not simulator secdons and end the recording pyautogui.write('v', 0.5) time.sleep(10) pyautogui.write('v', 0.5)
Also if you are running a version of sofa that is not compatible with the recording functionality in SofaPython3 or for whatever reason you can’t get that recoding to work there is a work around I have found. If you have a headless server with sofa installed on it you can record videos with the following (tested with python3 code).
import time import subprocess class SofaRecorder: def __init__(self, running_on_headless_server=False): self.x_server = None self.pyautogui = None self.headless = running_on_headless_server def start_x_server(self): if self.x_server == None and self.headless: self.x_server = subprocess.Popen(["sudo","X","-config", "/dummy.conf"]) time.sleep(3) #wait for process to get online # pyautogui cannot be imported until there is a display to connect to process launches import pyautogui self.pyautogui = pyautogui def start_recording(self): self.start_x_server() time.sleep(1) self.pyautogui.write('v') def stop_recording(self): self.pyautogui.write('v') time.sleep(1) def stop_x_server(self): subprocess.Popen(["sudo", "kill", str(self.x_server.pid)]) time.sleep(1) self.x_server = None # example of usage if __name__ == "__main__": recorder = SofaRecorder(running_on_headless_server=True) # if the x_server is not started before the sofa gui launches # the sofa process will seg fault recorder.start_x_server() # without the -g batch option this launches a sofa gui sofa_process = subprocess.Popen(["runSofa", "--start"]) recorder.start_recording() print('recording started') time.sleep(30) #note this records for 10 wall clock seconds not seconds in the simulator recorder.stop_recording() print('recording stoppped') time.sleep(3) sofa_process.terminate() print("sofa terminated") time.sleep(3) recorder.stop_x_server() print('x server terminated')
These are the dependencies I had to install on my docker container which already had sofa set up in it:
sudo PIP_TARGET=/usr/lib/python3.7/dist-packages python3.7 -m pip install \ pynput pyautogui sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-tk python3-dev sudo apt-get update sudo apt-get install -y xserver-xorg-video-dummy x11-utilss export DISPLAY=:0
and dummy.conf is
Section "Monitor" Identifier "Monitor0" HorizSync 28.0-80.0 VertRefresh 48.0-75.0 # https://arachnoid.com/modelines/ # 1920x1080 @ 60.00 Hz (GTF) hsync: 67.08 kHz; pclk: 172.80 MHz Modeline "1920x1080_60.00" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 -HSync +Vsync EndSection Section "Device" Identifier "Card0" Driver "dummy" VideoRam 256000 EndSection Section "Screen" DefaultDepth 24 Identifier "Screen0" Device "Card0" Monitor "Monitor0" SubSection "Display" Depth 24 Modes "1920x1080_60.00" EndSubSection EndSection
-
AuthorPosts
- You must be logged in to reply to this topic.