I've compiled opencv from source and installed it on a rpi3 Jessie (full) and I decided to do the same on a new rpi3 but with Jessie light this time. However when I try to run some of the examples, I am being told:

error: Gtk-WARNING **: cannot open display

(I run the pi with keyboard and a screen for this).

I have installed libgtk2.0-dev and opencv was built with the option WITH_GTK=ON.

Is it possible to have a frame to open in Jessie Light from within the console? What do I need for this? If it's not possible, what should I install to have my application to show in a frame: do I have to install a full GUI?

As a small step forward I have installed lightdm, xorg and xinit and now I have a small white terminal frame which opens at the top left of my 21" monitor, and now I can run my opencv application which opens within that frame.

  • Do you use the opencv you compiled on the other system? – Philippos Jul 6 '17 at 11:34
  • Cannot open display is indeed a message from a standard GUI application looking for an Xorg server. – goldilocks Jul 6 '17 at 13:37
  • @Philippos no I compiled it directly on the pi. – calocedrus Jul 7 '17 at 0:05
  • @goldilocks that explains then the absence of the message after I've installed Xorg, but the result is less than satisfying (small terminal and the graphical opencv application opens in and partially overlaps the terminal). – calocedrus Jul 7 '17 at 0:09
  • That's why people generally run a window manager or desktop environment on top of X. Bare X is very minimal. This doesn't mean you can't do it that way, just you will have to dig in to figure out how. -> unix.stackexchange.com – goldilocks Jul 7 '17 at 12:19

As far as i know, you can't run OpenCV, nor GTK, in graphical mode from console mode.

GTK needs to be run on X11 or Wayland.
OpenCV can work with other display manager, but no one of them will be windowsed when launched from console.

For python : you can use pygame, pythonic bindings of SDL1.2, able to display graphics and manage user events in console mode.

A simple conversion from openCV frame to pygame surface will allow you to manage and display OpenCV frames on screen :
pygameSurface = pygame.surfarray.make_surface(CVframe.swapaxes(0, 1))

Note that this approach is quite easy to implement, but can be a bit slow if you work with video in high definitions.

For C++ : you can work with SDL, OpenGL, openMax, or dispmanx.
I only worked with SDL :
- allow user event management
- not accelerated
- well documentated
and dispmanx :
- no user event management
- GPU accelerated, provide multiple layer display
- less documentated

| improve this answer | |
  • That depends. The gtk-examples rely on X11, I think, thus the "cannot open display" message. But we have an opencv application streaming the output to the framebuffer without X11. – Philippos Jul 6 '17 at 11:41
  • If you show us your method, you'll get my vote :) – Technico.top Jul 6 '17 at 12:19
  • 1
    It's a qt5 application running with QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0. The cv::Mats retrieved from the camera are filtered and converted to QImage to be displayed. But this is not what the OP wants, having a "light" distribution by replacing X11 and gtk with qt5 ... (-; – Philippos Jul 6 '17 at 13:33
  • @Philippos "having a "light" distribution by replacing X11 and gtk with qt5" indeed this wasn't my purpose, and moreover I didn't build opencv with Qt support (so i'd have to recompile opencv, > 60mn each time!) – calocedrus Jul 7 '17 at 0:12
  • @Technico.top that's a solution, but not if I use opencv with C++ programs. And i'm using 3.6, haven't checked pygame on this (should work though) – calocedrus Jul 7 '17 at 2:59

You need an X enviroment to use these OpenCV features , so install it :

sudo apt-get install xserver-xorg-core xserver-xorg-input-all \
xserver-xorg-video-fbdev libx11-6 x11-common \
x11-utils x11-xkb-utils x11-xserver-utils xterm lightdm openbox
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.