Thursday, 30 June 2016

Setting up OpenCV with Qt Creator on Windows (without CMake)

This tutorial will cover the easiest way to install OpenCV 2.4.9 with Qt 5.4.1, without using CMake, which can be very helpful for beginners who do not want to invest time to make their own build. There might be more updated versions of both the softwares but the essential components are still the same.




OpenCV (Open Source Computer Vision) is an open source platform which consists of function aimed at real time computer vision. It can be used to make various image processing and computer vision applications with the help of its powerful libraries. 

Qt is a cross-platform application framework that is widely used for developing application software that can be run on various software and hardware platforms with little or no change in the underlying codebase. It is the open-source competitor to the popular windows development platform Visual Studio.

Download Links :-

Note:- Please use only the versions of the softwares mentioned in this tutorial. It will NOT work for other versions of Qt and OpenCV. 
Please let us know if the download links don't work.

Installation Steps :-
  1. Install Qt using the setup file you just downloaded. You may install it in the default location or any other location as you wish with only one restriction. There cannot be any spaces in the installation path. For example:- F:\Qt\Qt5.4.1' is a valid installation location whereas 'F:\Qt\Qt 5.4.1' is not. 
  2. Extract OpenCV using the self-extracting archive that you just downloaded. Again, remember that there cannot be any spaces in the extraction location else Qt won't be able to read it. After extraction, you'll get two folders in that location- 'build' and 'sources'.
  3. Extact the OpenCV build in the same way. Now you'll get two folders called 'include' and 'build-qt' and a text file.
  4. Let's say you extracted the build to 'F:\OpenCV-2.4.9'. You will get a folder called 'build-qt' in that directory. To enable Qt finding the libraries of OpenCV, the location 'F:\OpenCV-2.4.9\build-qt\bin' has to be added to the System Path variable. You can find a way to do that here. Make sure you add this path to the end of the list. Do NOT replace the contents of the PATH variable. To ensure that you've added it, open a Command Prompt window and type 'path' and hit enter. Make sure that you can see the location there.
  5. Now we're ready to test our installation.

Running OpenCV with Qt for the first time :-
  1. Start Qt. Click on New Project -> Qt Console Application.
  2. Name your project and set the project location and click Next.
  3. You'll have two files in your project. A .pro file and a .cpp file. You will now need to add a few  things to the .pro file. Open it up on Qt by clicking on it.
  4.  Open the text file (OpenCV Include text for Qt.txt) that came with the build for OpenCV and copy its contents. Paste it at the end of the .pro file.
  5. Next, you have to edit the INCLUDEPATH and the LIBS variables. Remeber, you have to edit them according to the location where you extracted the build for OpenCV. Also note that the double slashes ('\\') in the INCLUDEPATH are very important. Please do not use single slashes for the path. For the LIBS variable, the '-l' (hyphen small L) in the beginning and the '\' (backslash) in the end are also important. 
  6. Once you make the updates in step 5 to your .pro file, update these in the .txt file too because you will need to add this to the .pro file every time you make a new project. 
Running your first example :- 
  1. Download this code and paste it in the .cpp file. 
  2. Edit the variable imgloc to the location of any image file present in your PC. Here you can either use forward slashes ('/') or double back slashes ('\\') as a file path separator.
  3. Hit 'Run' (Green button on the left side) or press 'Ctrl + R' and you should see something like this.

If you can't follow this tutorial, here's a video tutorial for the same.




3 comments:

  1. sorry sir,
    the third part.mean's
    qt based opencv build can not download.
    what to do further.

    ReplyDelete
  2. i am trying to configure opencv2.4.9 with qt5.4.1 creator.
    using the above method but unfortunately the third part can not download.

    ReplyDelete
  3. Same problem here...... i cant download build
    please share another link

    ReplyDelete