p-v-o-s / infrapix

converting infragram vid files to NDVI
48 stars 21 forks source link

Headless scenario error: _tkinter.TclError: no display name and no $DISPLAY environment variable #5

Open 0b1-k opened 10 years ago

0b1-k commented 10 years ago

When using infrapix on a Raspberry Pi from the command line, the following error occurs. It would be great to be able to use infrapix in headless scenarios. Thanks and regards.

root@hgbnoircam:/home/hygrowbot/pics# infrapix_single -i 2014-01-02-17:28:16.337740.jpg --show_histogram -o ndvi.jpg Rendering infrablue input image '2014-01-02-17:28:16.337740.jpg' to NDVI output image 'ndvi.jpg' 2014-01-02-17:28:16.337740.jpg ndvi.jpg Converting to NDVI... Traceback (most recent call last): File "/usr/local/bin/infrapix_single", line 9, in load_entry_point('infrapix==dev', 'console_scripts', 'infrapix_single')() File "/usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/commands/single.py", line 139, in main app.render() File "/usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/commands/single.py", line 43, in render self.render_single(kwargs) File "/usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/commands/single.py", line 53, in render_single ndvi(self.input_file,self.output_file,self.ndvi_kwargs) File "/usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/process_infrablue.py", line 115, in ndvi fig=plt.figure(figsize=(fig_w,fig_h),dpi=dpi) File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 343, in figure kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 80, in new_figure_manager window = Tk.Tk() File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in init** self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable

rperezperez commented 10 years ago

Hello,

try with this:

  1. nano /usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/process_infrablue.py
  2. append the following code:

import matplotlib matplotlib.use('Agg')

before the line: import matplotlib.image as mpimg

  1. save the file

Best, Ramón

0b1-k commented 10 years ago

Thank you Ramón :) I'll give this a try this weekend and will report back. Cheers, -Fabien.

0b1-k commented 10 years ago

Hi Ramón,

I made the suggested change to the /src/process_infrablue.py then rebuilt, re-installed, and ran a test with the fix.

During the test, the following warning messages showed up but the code didn't crash :) Yay! Progress :)

root@hgbnoircam:/home/hygrowbot/pics# infrapix_single -i latest.jpg --show_histogram -o latest_noir.jpg Rendering infrablue input image 'latest.jpg' to NDVI output image 'latest_noir.jpg' latest.jpg latest_noir.jpg Converting to NDVI... /usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/process_infrablue.py:79: RuntimeWarning: invalid value encountered in divide arr_ndvi = num/denom /usr/lib/pymodules/python2.7/matplotlib/colorbar.py:686: RuntimeWarning: invalid value encountered in greater in_cond = (xn > -0.001) & (xn < 1.001) /usr/lib/pymodules/python2.7/matplotlib/colorbar.py:686: RuntimeWarning: invalid value encountered in less in_cond = (xn > -0.001) & (xn < 1.001) /usr/lib/pymodules/python2.7/matplotlib/colors.py:533: RuntimeWarning: invalid value encountered in less cbook._putmask(xa, xa<0.0, -1)

We're on the right track, however, the resulting image was nearly entirely black as you can see below:

latest_noir

rperezperez commented 10 years ago

Hi Fabien,

do you remember if you moved the camera while taking the picture? I have sometimes the same effect, but I rebooted it and it was solved the problem :(

Best, Ramón

Fabien Royer wrote:

Hi Ramón,

I made the suggested change to the /src/process_infrablue.py then rebuilt, re-installed, and ran a test with the fix.

During the test, the following warning messages showed up but the code didn't crash :) Yay! Progress :)

root@hgbnoircam:/home/hygrowbot/pics# infrapix_single -i latest.jpg --show_histogram -o latest_noir.jpg Rendering infrablue input image 'latest.jpg' to NDVI output image 'latest_noir.jpg' latest.jpg latest_noir.jpg Converting to NDVI... /usr/local/lib/python2.7/dist-packages/infrapix-dev-py2.7.egg/infrapix/process_infrablue.py:79:

RuntimeWarning: invalid value encountered in divide arr_ndvi = num/denom /usr/lib/pymodules/python2.7/matplotlib/colorbar.py:686: RuntimeWarning: invalid value encountered in greater in_cond = (xn > -0.001) & (xn < 1.001) /usr/lib/pymodules/python2.7/matplotlib/colorbar.py:686: RuntimeWarning: invalid value encountered in less in_cond = (xn > -0.001) & (xn < 1.001) /usr/lib/pymodules/python2.7/matplotlib/colors.py:533: RuntimeWarning: invalid value encountered in less cbook._putmask(xa, xa<0.0, -1)

We're on the right track, however, the resulting image was nearly entirely black as you can see below:

latest_noir https://f.cloud.github.com/assets/1403215/1957481/995b4a8c-8209-11e3-8553-6f60c8da1d04.jpg

— Reply to this email directly or view it on GitHub https://github.com/Pioneer-Valley-Open-Science/infrapix/issues/5#issuecomment-32789787.

0b1-k commented 10 years ago

Hi Ramón,

The source images aren't the issue:

. the IR camera itself is rigged at a fixed location and never moves . the IR images themselves are perfectly clear and focused

It's only when processing the IR pictures through the infrapix code with the recommended changes

import matplotlib matplotlib.use('Agg')

that the color mapping stops working (see the Runtime warnings)

I hope this clarifies things a bit.

Thank you,

Best regards, -Fabien.

hardtoneselector commented 10 years ago

same issue here, running on odroid u3 (modified ubuntu) but not in a headless enviroment. with the imort mathlib I was get rid of the tkinter error and then i recieved the black screen,... @Fabien: did you found a workarround? Thanks Best Regards Bernhard

0b1-k commented 10 years ago

Hi Bernhard,

Unfortunately, this issue had to be put on the back burner and I did not investigate it any further, at least for the time being.

Best regards, -Fabien.