OpenCV with QT – Installation, configuration, problems and solutions
If you don’t know yet, OpenCV is a free library for image processing and computer vision applications. You can find more info from their web site.
So why QT ?
OpenCV can be used mainly in programs written in C and C++ (not only that, there are so many wrappers which enables you to work with OpenCV in other languages too). So talking about C++ why not using Visual C++ ?? Of course you can easily design GUIs. But why QT ?
QT is an C++ IDE which can be used to create gui applications easily. Find more info here.
The main advantage in using QT is that we can easily “integrate” the GUIs of OpenCV inside the GUIs created with QT.( Correct me if I’m wrong) What it means is that, It is hard to insert a video window inside a form created with C#. If you are using Visual Studio the window will open seperately to display the video. Think you got the point. Do some research, you’ll find the importance.
So let’s go to the topic..
Installing and configuring QT to work with OpenCV in Windows
FIrst we need to download and install the complete QT SDK. Download it here and get it installed. ( I have installed Qt SDK version 1.1.4 which includes the QT Creator IDE version 2.3 into the folder “C:\QtSDK”)
Install CMake. Download it here. (I used CMake 2.8.2)
Download OpenCV-2.2.0-win.zip and extract it to a folder (In my case it is C:\OpenCV2.2 ). I’m using the version 2.2 here. Newer versions also can be used in the same way i describe here with minor changes.
Now we need to comiple the OpenCV libraries. Run the CMake GUI.
Now give the source folder ( Mine is C:\OpenCV2.2) and create a folder for the binaries to be build (my case it is C:\OpenCV2.2MinGw ) and give the path to the “Where to build binaries” box.
Now press configure. Select the generator as MinGW Makefiles.
And select Use default native compilers and press finish.
Wait some time and you’ll get a configuration screen.
Set “DEBUG;RELEASE” for CMAKE_BUILD_TYPE.
If you like you can check the box for BUILD_EXAMPLES, so you can play with the examples
Now press configure again.
Now you’ll see a similar window to the last one and it asks for the path of qmake.exe. You need to puth the path to the qmake.exe here.
For me it is
Press configure again.
Now press Generate, so it will try to generate the makefiles.
“Missing libgmp-10.dll” problem
Most probably you’ll get a message saying that missing libgmp-10.dll is missing. Solution is simple just add the bin folder of MinGW to the System Path variable
( My Computer -> View System Information -> Advanced -> Environment Variables -> System Variables -> Path -. Edit (or New) )
In my case this path is
Now you are ready to proceed. Press generate button of the CMake window again.
Now you’ll get the required files in the folder which you gave as build folder above. Now we need to compile these files with MinGW.
Open Command Prompt and change your directory to the build folder
Now give the command
Have a nap because it takes some time for this process to complete
After completion of step 9 give the command
You are DONE!
Playing with QT : Check whether everything is working fine..
Download this. Double Click and open the Sanj.pro file. It will be opened with QT Creator.
In the Sanj.pro file change the paths “INCLUDEPATH” and “LIBS”, if you used paths other than the ones I used.
Now run the project. Enjoy using QT
Good books I have come across :
- For OpenCV with QT : OpenCV 2 Computer Vision Application Programming Cookbook book (Packt Publishers) (This is where I took the above simple example)
- For learning OpenCV : Learning OpenCV – O’Reilly Media