Using OpenCV 2.3 with QTCreator in Windows

OpenCV loves QTCreator

UPDATE

If you’re trying to compile opencv look at this article.

This is an update to my “Using OpenCV within QTCreator in Windows” post, that will show you how to quickly setup OpenCV 2.3 for QTCreator in Windows. (This of course will work for any IDE, not just QTCreator).

So, let’s get down to the details quickly:

  1. Download both OpenCV and QTCreator, which can be found by clicking on the links.
  2. Install QTCreator (let it do its thing and restart the computer after it’s done)
  3. Install OpenCV
  4. OpenCV 2.3 for windows has a self-extracting executable called:   OpenCV-2.3.1-win-superpack.exe)
  5. Extract the files to a directory of your liking.
  6. Remember that the directory’s name should have no white spaces (For example:   C:\OpenCV2.3.1\)
  7. Cut the file “opencv.hpp” found in C:\OpenCV2.3.1\build\include\opencv2\    and paste it in the directory   C:\OpenCV2.3.1\build\include
  8. OpenCV 2.3 offers several pre-compiled libraries.  They are found in the subdirectory \build (For example:  C:\OpenCV2.3.1\build\), as seen in the following image:
  9. Pick which pre-compiled library to work with
  10. For example I picked the one with GPU support for x86 systems found in the subdirectory:  \build\gpu\x86\
  11. The chosen directory will have two more subdirectories:
  12. Subdirectory \bin\      which contains the dll files
  13. Copy the dll files and paste them into either:  your program’s executable directory or in the windows system directory (system32 for 32bit windows or SYSWOW64 for 64bit windows)
  14. Subdirectory \lib\   which contains the lib files to link to
  15. Finally we’re onto running QTcreator
  16. Start a New Project (File->New File or Project… Then pick a QT c++ project, could be QT application or Console application, then follow the instructions to create the new project)
  17. Or open a project that you were already working on
  18. Now that you have an open project, click on the “Edit” button on the left pane of QTCreator as shown below:
  19. Once in the edit pane, you will see a list of files.
  20. Double click on the project file to open it (the file with the “.pro” file extension).
  21. All we have left to do, is to add the INCLUDEPATH and LIBS lines to your pro file, like the ones shown below, but remember to use the actual directory where you installed OpenCV.  (Backward slashes are used to add multiple lines)
  22. INCLUDEPATH += C:\OpenCV2.3.1\build\include \
    
    CONFIG(release,debug|release)
    {
        LIBS += C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_calib3d231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_contrib231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_core231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_features2d231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_flann231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_gpu231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_haartraining_engine.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_highgui231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_imgproc231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_legacy231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_ml231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_objdetect231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_ts231.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_video231.lib
    }
    
    CONFIG(debug,debug|release)
    {
        LIBS += C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_calib3d231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_contrib231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_core231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_features2d231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_flann231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_gpu231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_haartraining_engined.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_highgui231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_imgproc231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_legacy231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_ml231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_objdetect231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_ts231d.lib \
                C:\OpenCV2.3.1\build\gpu\x86\lib\opencv_video231d.lib
    }
    
  23. Now the last thing is, in your file that will use the opencv functions include the opencv by putting the following statement in your code:
  24. #include
    

Note: If you have a chance, check out the BarbatoLabs Image API, blImageAPI. It’s a very simple but powerful API, which is based on opencv’s IplImage and boost::shared_ptr, and gives you automatic garbage collection and memory allocation/deallocation and other good stuff, while being 100% compatible with opencv’s existing algorithms, it can be used instead of IplImage or interchangeably with it.

It makes using opencv a breeze

Troubleshooting List, to be built as I get feedback:

  1. Error —  “exited with code – 1073741515” (or something along those lines)
    1. You probably missed Step 3. — Restart the computer after installation of OpenCV, (a quick restart should resolve the problem).
    2. If you still get the error after restarting, then copy the OpenCV dlls from the OpenCV2.2/bin directory to the Windows system32 directory if in 32bit version of windows or to the Windows SYSWOW64 directory if in 64bit version of windows
    3. If you still get the error after the above steps, then you’re missing some Microsoft dlls.  It turns out that the “debug” version of opencv has some dependencies on Microsoft dlls.  The “release” version is good to go out of the box.
      1. [SOLVED] — It turns out that the Microsoft dlls are downloaded as part of the visual c++ express package.  So as a solution, download and install the bare-bones visual c++ express and the “debug” version of opencv will work.  (You don’t have to use visual c++ express, you can still use QTcreator and the Mingw compiler, it will work, trust me).
  2. If you get errors such as “cannot find cv.h file” and something like that, look at the steps above, where I mentioned to cut and past the “opencv.hpp” file in the correct directory.
  3. Error — “underfined reference cv::VideoCapture” or any other opencv c++ function like cv::mat and others
    1. After some googling, the consensus is that to use the c++ features of opencv with Mingw, opencv has to have been compiled using g++ instead of gcc. Follow the instructions at this link to compile opencv c++ for QTcreator in windows.
    2. Note:  If you want c++ like ease and usability with the opencv c functions, while maintaining full compatibility with the c functions, then use the Barbato Labs Image library.

About Vincenzo Barbato

Known to his friends as Enzo, he's an outside-the-box engineer/researcher whose interests and expertise span many fields, including controls systems, multi-physics simulations, mechatronics, oil technologies, data analysis and machine vision just to name a few.

Refusing to grow up, he's on a continuous journey to develop simple and creative solutions that have the power of disrupting industries by optimizing systems and processes.

Married to a beautiful wife, with two beautiful daughters and two identical twin boys, his home is a never ending chaotic fountain of inspiration.

His outlook on life:

"Never blindly accept what you're told, listen, but then question, with curiosity, creativity and collaboration we can change the world"

About Enzo

Known to his friends as Enzo, he's an outside-the-box engineer/researcher whose interests and expertise span many fields, including controls systems, multi-physics simulations, mechatronics, oil technologies, data analysis and machine vision just to name a few. Refusing to grow up, he's on a continuous journey to develop simple and creative solutions that have the power of disrupting industries by optimizing systems and processes. Married to a beautiful wife, with two beautiful daughters and two identical twin boys, his home is a never ending chaotic fountain of inspiration. His outlook on life: "Never blindly accept what you're told, listen, but then question, with curiosity, creativity and collaboration we can change the world"

Leave a Reply

Your email address will not be published. Required fields are marked *