1
votes

I have got an error :

Gtk-WARNING **: cannot open display:

  1. Below is the simple image display program in opencv using C++ and in raspberry pi 3 Model B

  2. I understood " Imshow " function which create a window to display image in GUI will not work in terminal

  3. I am using headless connection (with LAN connection - SSH through Putty, raaspberry pi desktop access through VNC )

Code:

#include<opencv2/highgui/highgui.hpp>
using namespace cv ;
int main() {
    Mat img = imread("/home/USER/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR);
    imshow("opencvtest",img);
    waitKey(0);
    return 0;
}

Getting the error:

$ g++ -ggdb pkg-config --cflags opencv -o basename opencvtest.cpp .cpp opencvtest.cpp pkg-config --libs opencv

$ ./opencvtest

" (opencvtest:1927): Gtk-WARNING **: cannot open display"

Just help me running a simple program and let me know how can i achieve this . I am newbie to raspberry pi .

Thanks Atila

1
what is your desktop environment? You could use X11 forwarding on PuTTy. Install XMing for Windows (i assume windows because of PuTTy) - Nick

1 Answers

0
votes

Try the following command, prior to the execution of the application.

export DISPLAY=:0.0