Displaying GpuMat using imshow in opencv4tegra

Hi,

I have been developing an application using opencv4tegra in JetsonTX1 board. For optimizing the application I tried to display gpuMat using imshow. And also it is stated in imshow documentation that it supports gpuMat provided window should have OpenGL support.

So I created window using OpenGL support and gave gpuMat frame to imshow,but while executing imshow gives the following error.

OpenCV Error: No OpenGL support (Library was built without OpenGL support) in cvNamedWindow, file /hdd/buildbot/slave_jetson_tx_4/35-O4T-L4T-R24-armhf/opencv/modules/highgui/src/window_gtk.cpp, line 845
terminate called after throwing an instance of 'cv::Exception'
  what():  /hdd/buildbot/slave_jetson_tx_4/35-O4T-L4T-R24-armhf/opencv/modules/highgui/src/window_gtk.cpp:845: error: (-218) Library was built without OpenGL support in function cvNamedWindow

Am I missing something. Any help will be appreciated.
Thanks in advance

Was this a local login, or a remote login? If remote, it is probably trying to use the OpenGL and OpenCV of the machine you are physically at.

We are using local login. Not tried in the remote login(using ssh).

See if all of the nVidia-specific files are in place:

sha1sum -c /etc/nv_tegra_release

…all should be “ok”, but the one of most interest is if this one shows ok:

/usr/lib/xorg/modules/extensions/libglx.so

Yes.
/usr/lib/xorg/modules/extensions/libglx.so shows OK.

So far it seems files are installed correctly, and display is local, so a remote display is not involved. I probably can’t answer what went wrong, but you said you used imshow…this is probably where things went wrong. As an example, perhaps imshow requires a different version of OpenGL. Can you give any command line you used with imshow to get the error? Someone answering the question will probably want to be able to reproduce the issue.

Hi,

The sample source code is given below:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/gpu/gpu.hpp>

using namespace cv;

int main()
{
    unsigned long AAtime=0, BBtime=0;

    Mat img;
    Mat outimg, outimg2;
    img = imread("pexels-photo.jpg",0);
    gpu::GpuMat d_src, d_dst;

    d_src.upload(img);
    AAtime = getTickCount();
    gpu::Canny(d_src, d_dst, 35, 200, 3);
    BBtime = getTickCount();

    printf("cuda %.5lf \n",  (BBtime - AAtime)/getTickFrequency() );
    d_dst.download(outimg);


    AAtime = getTickCount();
    Canny(img, outimg2, 35, 200, 3);
    BBtime = getTickCount();
    printf("cpu %.5lf \n",  (BBtime - AAtime)/getTickFrequency() );

    namedWindow("t",WINDOW_OPENGL);
    imshow("t",d_dst);

    cvWaitKey(0);
    return 0;
}

And when running the following error is shown.

OpenCV Error: No OpenGL support (Library was built without OpenGL support) in cvNamedWindow, file /hdd/buildbot/slave_jetson_tx_4/35-O4T-L4T-R24-armhf/opencv/modules/highgui/src/window_gtk.cpp, line 845
terminate called after throwing an instance of 'cv::Exception'
  what():  /hdd/buildbot/slave_jetson_tx_4/35-O4T-L4T-R24-armhf/opencv/modules/highgui/src/window_gtk.cpp:845: error: (-218) Library was built without OpenGL support in function cvNamedWindow

Aborted

After you’ve compiled the application, run "ldd " to see what it links against (it might differ from other Jetsons if the environment is different). The sample application plus info on linking on your particular Jetson should be enough to start finding where it went wrong.

the opencv for tx1 was build only with gtk and gdk, call any opengl api will case the program exit
and output some assert information

how to show the image,? you can lookup the window_gtk.cpp and window.cpp in opencv souce code.

this the segment, it must be exit at here
#ifndef HAVE_OPENGL
if (flags & CV_WINDOW_OPENGL)
CV_ERROR( CV_OpenGlNotSupported, “Library was built without OpenGL support” )
;
#else
if (flags & CV_WINDOW_OPENGL)
createGlContext(window);

window->glDrawCallback = 0;
window->glDrawData = 0;

#endif

You know? I am honestly very frustrated by this issue… it is back from tk1 times that opencv4tegra package is missing this features. I don’t understand why it was built without opengl support. There is nothing even remotely usable that you can do with imshow without this. It makes unnecessarily complicated to design some basic opencv applications.

Is it possible that this can be addressed in the future? Because in the past I have tried to compile opencv from scratch but then it was impossible to get CPU acceleration. Either opengl or cpu optimizations, not a very appealing option.

Does someone knows how to compile opencv4tegra getting opengl support, cpu optimization and GPU support? I failed to accomplish this in the past.

thanks

Bumping this thread from the dead because I am having this same issue and it is very frustrating.

How can we build OpenCV with OpenGL support for the TX2??? Is it possible?

You may check https://devtalk.nvidia.com/default/topic/1007290/jetson-tx2/building-opencv-with-opengl-support-/post/5141945/#5141945