sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Exporting graphics on a headless Pi

Fri Nov 22, 2013 3:02 pm

Mathematica can not export any format of graphics witohut the front-end running. It will display these error messages:

Code: Select all

In[3]:= p=Plot[Sin[x],{x,0,2 Pi}]

Out[3]= -Graphics-

In[4]:= Export["testplot.png",p]

Developer`LaunchFrontEnd::nxsrv: An x server is required for that operation.

Rasterize::nofe: A front end is not available; Rasterize requires a front end.

Out[4]= $Failed
To be able to export graphics on a Pi that does not run a front-end, for example on a headless server, you have to install Xvfb (or a similar program that emulates a display).
Then you start mathematica like this if you want 24 bit graphics:

Code: Select all

xvfb-run -s "-screen 0 640x480x24" /opt/Wolfram/WolframEngine/10.0/Executables/math
or if you want 8 bit graphics:

Code: Select all

xvfb-run -s "-screen 0 640x480x8" /opt/Wolfram/WolframEngine/10.0/Executables/math
And it will work:

Code: Select all

In[1]:= p=DensityPlot[{Sin[Sqrt[x] + Log[y]]}, {x, 0, \[Pi]^2}, {y, 0, E^\[Pi]}]

Out[1]= -Graphics-

In[2]:= Export["testplot24.png",p]

Out[2]= testplot24.png
(On my first-gen 256 MB model B it takes about 50 seconds to render the graphics with 24 bit colors.)
Last edited by sharix on Fri Nov 22, 2013 6:18 pm, edited 1 time in total.

dennisw
Posts: 18
Joined: Fri Nov 22, 2013 7:06 am

Re: Exporting graphics on a headless Pi

Fri Nov 22, 2013 5:35 pm

I just ssh -X into my Pi. In other words, I use X forwarding. There shouldn't be any need for a virtual frame buffer or something like xvnc. Please let me know if the following doesn't work for you.

In /etc/ssh/sshd_config on the Pi, change X11Forwarding to yes in order to enable it.

For your PC, ssh -X works from the command line in Linux. In Putty on Windows, set Enable X11 Forwarding in Connection > SSH > X11
raspberrypi.stackexchange.com --- mathematica.stackexchange.com

Arnoud
Posts: 9
Joined: Thu Jul 18, 2013 3:52 pm

Re: Exporting graphics on a headless Pi

Fri Nov 22, 2013 6:08 pm

I have been using tightvncserver to have the graphics rendered. The first time around it is a bit pokey, but subsequent graphics exports are better (usually about 1s or so):

Code: Select all

[email protected] ~ $ tightvncserver :42

New 'X' desktop is raspberry-wri2:42

Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberry-wri2:42.log

[email protected] ~ $ export DISPLAY=:42
[email protected] ~ $ wolfram
Wolfram Language (Raspberry Pi Pilot Release)
Copyright 1988-2013 Wolfram Research
Information & help: wolfram.com/raspi

In[1]:= Export[ "test.png", Plot[0,{x,0,1}] ]

Out[1]= test.png

In[2]:= Export[ "test.png", Plot[0,{x,0,1}] ] // AbsoluteTiming

Out[2]= {1.056819, test.png}

In[3]:=

sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Re: Exporting graphics on a headless Pi

Fri Nov 22, 2013 6:10 pm

dennisw wrote:I just ssh -X into my Pi. In other words, I use X forwarding. There shouldn't be any need for a virtual frame buffer or something like xvnc. Please let me know if the following doesn't work for you.

In /etc/ssh/sshd_config on the Pi, change X11Forwarding to yes in order to enable it.

For your PC, ssh -X works from the command line in Linux. In Putty on Windows, set Enable X11 Forwarding in Connection > SSH > X11
This of course works, but is not practical if you want to run automated mathematica scripts that export graphics, which is what I wanted to do.

I will try with tightvncserver, some speedup from xvfb would be nice. However, xvfb also becomes faster if graphics are rendered more than once per session:

Code: Select all

In[1]:= p=DensityPlot[{Sin[Sqrt[x] + Log[y]]}, {x, 0, \[Pi]^2}, {y, 0, E^\[Pi]}]

Out[1]= -Graphics-

In[2]:= Export["testplot.png",p]//AbsoluteTiming

Out[2]= {43.213339, testplot.png}

In[3]:= Export["testplot.png",p]//AbsoluteTiming

Out[3]= {8.626120, testplot.png}

In[4]:= Export["testplot.png",p]//AbsoluteTiming

Out[4]= {8.615019, testplot.png}

In[5]:=

edit: tried with tightvncserver:

Code: Select all

In[1]:= p=DensityPlot[{Sin[Sqrt[x] + Log[y]]}, {x, 0, \[Pi]^2}, {y, 0, E^\[Pi]}]

Out[1]= -Graphics-

In[2]:= Export["testplot.png",p]//AbsoluteTiming

Out[2]= {143.703919, testplot.png}

In[3]:= Export["testplot.png",p]//AbsoluteTiming

Out[3]= {15.838517, testplot.png}

In[4]:= Export["testplot.png",p]//AbsoluteTiming

Out[4]= {4.204656, testplot.png}

In[5]:= Export["testplot.png",p]//AbsoluteTiming

Out[5]= {3.641392, testplot.png}

In[6]:=
It does get better eventually but for the first time xvfb is way faster.

rgall
Posts: 1
Joined: Sun Apr 13, 2014 2:09 pm

Re: Exporting graphics on a headless Pi

Sun Apr 13, 2014 2:26 pm

I am trying output graphics from the command line from a remote shell .
I have executed the following script

Code: Select all

sudo xvfb-run -s "-screen 0 640x480x24" -e /dev/stdout /opt/Wolfram/WolframEngine/10.0/Executables/math
The follow is output
  • [[dix] Could not init font path element /usr/share/fonts/X11/misc, removing from list!
    [dix] Could not init font path element /usr/share/fonts/X11/cyrillic, removing from list!
    [dix] Could not init font path element /usr/share/fonts/X11/100dpi/:unscaled, removing from list!
    [dix] Could not init font path element /usr/share/fonts/X11/75dpi/:unscaled, removing from list!
    [dix] Could not init font path element /usr/share/fonts/X11/100dpi, removing from list!
    [dix] Could not init font path element /usr/share/fonts/X11/75dpi, removing from list!
    [dix] Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!list]

    I enter the following.

    Code: Select all

    In[1]:= p=DensityPlot[{Sin[Sqrt[x] + Log[y]]}, {x, 0, \[Pi]^2}, {y, 0, E^\[Pi]}]
    
    Out[1]= -Graphics-
    In[2]:= Export["testplot24.png",p]
    
    I still get the following:
    • Developer`LaunchFrontEnd::nxsrv: An x server is required for that operation.

      Rasterize::nofe: A front end is not available; Rasterize requires a front end.

      Out[4]= $Failed
Any Ideas?

hal8000
Posts: 187
Joined: Fri Oct 04, 2013 5:22 pm

Re: Exporting graphics on a headless Pi

Fri Apr 18, 2014 10:12 am

If your Pi is running Rasbian then X forwarding is already enabled.

On your remote computer, start a terminal and type:
ssh -X [email protected]

(Replace 192.168.0.1 with your Pi's LAN address or hostname if you modified /etc/hosts )
and it should allow remote access. My second Raspberry Pi is headless and I've posted
a screenshot on img mur

http://i.imgur.com/frBg6j1.png

Hopefully you should be able to see that it works without any additional commands except
ssh -X The client is an Acer Aspire 5734 laptop running Linux Mint 16 with native resolution
of 1366x768. The density plot shown took less than 1 second, not tried anything more graphic
intensive yet.

hal8000
Posts: 187
Joined: Fri Oct 04, 2013 5:22 pm

Re: Exporting graphics on a headless Pi

Fri Apr 18, 2014 12:34 pm

Sorry, cant edit my previous post. On Rhasbian, running raspi-config and enabling SSH
enables X forwarding.

User avatar
R61zt
Posts: 64
Joined: Fri Feb 01, 2013 3:55 pm

Re: Exporting graphics on a headless Pi

Mon May 12, 2014 2:59 pm

I did things differently. The headless rPi was running a c program and top showed it to be less than 1% busy doing only that. So as not to disturb that critical process, I used cp <filename> <filename.bak> from the terminal of the ssh originating second rPi and then
scp <filename.bak> [email protected]:~<path/filename.bak>
where 192.168.xxx.yyy is the ip address of the controlling rPi, path/ is some location on the controlling rPi and filename.bak is the filename to create there.

If you are not used to <example> brackets in computerish explanations then get a pen and paper and try working out the relationship between
I am not an <insult>
and
I am not an idiot

This does not fix your problem with getting a headless rPi to work as a renderer and then send you a screenful. It does though show one way of getting results off a headless rPi to do some display work with elsewhere.

dennisw
Posts: 18
Joined: Fri Nov 22, 2013 7:06 am

Re: Exporting graphics on a headless Pi

Tue May 13, 2014 5:23 am

R61zt wrote:I did things differently. The headless rPi was running a c program and top showed it to be less than 1% busy doing only that. So as not to disturb that critical process, I used cp <filename> <filename.bak> from the terminal of the ssh originating second rPi and then
scp <filename.bak> [email protected]:~<path/filename.bak>
where 192.168.xxx.yyy is the ip address of the controlling rPi, path/ is some location on the controlling rPi and filename.bak is the filename to create there.

If you are not used to <example> brackets in computerish explanations then get a pen and paper and try working out the relationship between
I am not an <insult>
and
I am not an idiot

This does not fix your problem with getting a headless rPi to work as a renderer and then send you a screenful. It does though show one way of getting results off a headless rPi to do some display work with elsewhere.
A little less rudeness could go a long way.

Note that angle brackets have significance in redirection and can be ambiguous when used as template-style markers. It's true that lots of people do use them that way - even me sometimes I think. Your examples work fine without them and there are even code markers here that will set commands apart from other text:

Code: Select all

cp filename filename.bak
raspberrypi.stackexchange.com --- mathematica.stackexchange.com

alexatwri
Posts: 12
Joined: Fri Nov 29, 2013 1:59 am

Re: Exporting graphics on a headless Pi

Fri Aug 01, 2014 3:58 pm

It might be worth noting that the process of starting a VNC session and providing a FE on the headless Raspberry Pi has been automated in the latest release (using turbovnc):

Code: Select all

In[1]:= Rasterize[Disk[]]                                                                                                                                                          

Out[1]= -Graphics-
The same limitations apply. It's slow when initializing the vnc session and FontEnd, but they then persist for the remainder of the session.

Return to “Mathematica”