Question

What is the best way to integrate and display an IplImage into a Qt GUI? Can this be done using OpenGL? If yes, how?

Was it helpful?

Solution

Well, I am answering my own question here.
I have been working with OpenCV since a year now and many times I have had to write code that opens a video file and streams it.
Lately, I have been using Qt to provide the high level gui and I came up with a solution to display IplImages on a Qt GUI using OpenGL(which I spent a lot of time struggling with but succeeded finally). Although, OpenCV can be built with Qt highgui support, I was keen in learning a bit of OpenGL and using it in my application.
I thought it would be helpful for people who need a basic framework for running videos for their applications.
This basic framework can be used in a wide range of applications like video content analysis, face recognition, pattern recognition and more. In the broader sense, this is basically a video player without audio support. So if you want you can add audio support and make this a video player. It will play almost all formats as opencv uses ffmpeg to play videos. I have created a C++ library for the same which I use quite extensively:

The main classes are:

QVideo : The main widget, providing functionality to open a video/rtsp stream and play it  
QIplImage: The core display widget. It's a QGLWidget which renders an IplImage
BackgroundWorker: This is a thread which runs in the background to retrieve images
from the stream. It is mandatory to run the frame grabber in a background thread,
otherwise it interferes with the GUI thread. All the image processing can be done in 
this thread

The source code is provided so you can modify it to your needs. Once the library is installed, you can use it in your qt application like so:

//Create an object
QVideo* video=new QVideo("Name",);
//set geometry (optional)
setCentralWidget(video);

To build the library, you will need qt and opencv(with ffmpeg support) installed. The library gets installed in /usr/lib or /usr/lib64 based on the architecture. The include files get installed in /usr/local/include Of course, all this can be changed in the project file if needed. To install, just unzip the package, and run qmake, make and sudo make install. Note: The project is configured for unix and would need to be changed for windows builds. Drop me a message for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top