I use namedWindow with openCV and get an error: (Image1): Gtk-WARNING **: cannot open display:"

The code is:

Mat image1 = imread("image1.jpg");

cv::namedWindow("image1");
cv::imshow("image1",image1);

waitKey(0);

Someone says he solves it by: "export DISPLAY=:0". But I don't really understand what does this solution mean.Since I am a beginner in opencv and c++. Could someone explain it in detail. e.g. How to add the code? Where to implement?

有帮助吗?

解决方案

You seem to be lacking the context of your X server.

The easiest way to make this work is to login graphically, then open a terminal, then start your application. This means, not opening a session for another user, e.g. root.

If you want to run the program as another user or from remote, you need other solutions. Please specify what you are doing. It is a common problem (it is about authorization) with common solutions depending on your use-case! It is not a OpenCV-related problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top