Using OpenCV within QTCreator in Windows

OpenCV loves QTCreatorUPDATE:  If you’re trying to compile opencv look at this article.

This is a quick post to answer a simple question that I have seen floating around the web with no definitive answer, using OpenCV in QTcreator.

Note:  Check out this other post for using OpenCV 2.2 in QTCreator within Windows.

Note:  Check out this new library for easily creating custom iterators blIteratorAPI

First off, stating the obvious, OpenCV is a state of the art open source library for image analysis from Intel, easy to use, and with a vast amount of tools that have been built up since its inception.

QTCreator is the open source cross-platform IDE from Nokia’s QT project, and with its ease of use, complete integration with the QT library, and included compiler, it has proven to be a complete solution.

For those of you that would love to use the OpenCV library from the QTCreator IDE, it turns out to be very simple.  Just follow the simple instructions below (if you already have OpenCV and QTCreator installed on your machine, just skip to step 3):

  1. Download both OpenCV and QTcreator, which can be found by clicking on the links.
  2. Install both OpenCV and QTcreator, specifying installation directories and so forth.  (I suggest just to let the automatic installation do its thing, and jog down the directories where OpenCV was installed).
  3. Restart the computer — This step is required for the PATH to be registered.  Trust me it will save you a huge headache.
  4. Run QTCreator
  5. 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)
  6. Now that you have a new project, you should have a view like the figure below.
  7. All you have left to do, is to add the INCLUDEPATH and LIBS lines to your pro file, like the ones shown in the figure below, but remember to use the actual directory where you installed OpenCV.  (Backward slashes “\” are used to add multiple lines)

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.0\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 step 1 and step 2, then you’re missing some Microsoft dlls.  It turns out that the “release” version of opencv works right out of the box.  But the “debug” version of opencv does not.  It has some dependencies on some Microsoft dlls.
      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)

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.

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"

39 Comments

  1. Hi
    I still get the “exited with code – 1073741515” error even when i did a restart after installing opencv. Can you maiby post a solution?
    Thanks!,
    Alex

  2. Hi Alex, the problem is that the shared library is not being found.  A reason could be that you did not let OpenCV set the enivronment variable path when it first installed.

    No worries, one thing you could do is copy the shared dlls into the windows\system32 directory if you’re using the 32bit version of windows or windows\SYSWOW64 if you’re using the 64bit version of windows.

    For example, copy libcv200.dll from your OpenCV2.0\bin directory to windows\system32 directory and do the same for all the other dlls

    After you’ve done that, it should work just fine.

    Let me know how it goes

  3. Hi navyenzo,
     
    Thanx for the quick reply! I got it working!
     
    Alex
     

  4. No problem.  Just remember from now on, whenever you get some weired “exited with code – XXXXXXXXX” result, it’s because it can’t find a shared library.

    In visual c++ on the other hand, it would start the program, but then it would show a message box saying it couldn’t find the “whatever” dll library it needs.

    You don’t necessarily have to copy the dlls to the windows/system32 directory, you could also copy them to your executable directory if you wanted.

    Good luck, and have fun experimenting with OpenCV.

  5. By far the best guide I’ve seen, however had to change the libs
    to read
    LIBS += C:\OpenCV2.1\lib\cv210.lib \
    C:\OpenCV2.1\lib\cvaux210.lib \
    C:\OpenCV2.1\lib\cxcore210.lib\
    C:\OpenCV2.1\lib\cxts210.lib \
    C:\OpenCV2.1\lib\highgui210.lib \
    C:\OpenCV2.1\lib\ml210.lib

    thanks for the help, been trying to get it to work for an hour, read your blog and got it done in 5 mins 🙂

  6. I’ve done all the same like in the tutorial.
    I’ve also tried similar configuration in Code::Blocks.
    If i use old OpenCV functions and structures like for example: IplImage present in all tutorials, the compilation process is fine.
    But when i try to use new ( OpenCV 2.1 ) classes like cv::VideoCapture i get 50+ errors like these:
     
    p, li { white-space: pre-wrap; }
    ./release\imagebuffer.o:imagebuffer.cpp:(.text+0x22f): undefined reference to `cv::fastFree(void*)’
    ./release\grabber.o:grabber.cpp:(.text+0x7e): undefined reference to `cv::VideoCapture::set(int, double)’
    ./release\grabber.o:grabber.cpp:(.text+0xaa): undefined reference to `cv::VideoCapture::set(int, double)’
    ./release\grabber.o:grabber.cpp:(.text+0xd6): undefined reference to `cv::VideoCapture::set(int, double)’
    ./release\grabber.o:grabber.cpp:(.text+0x102): undefined reference to `cv::VideoCapture::set(int, double)’
     
    Any help?

  7. One more thing. It works fine for raw OpenCV in Code::Blocks using Microsoft Visual C++ 2005/2008 compiler. It gives the same errors when trying to use GNU GCC Compiler.
    And when i try to use MVC 05/08 compiler after using qmake on my OpenCV + Qt Project, it won’t work.

  8. Hi again!
    Thank you for your quick response! I’ve been googling for a long time now, and i have found what was wrong.
    First of all, I had my libs built using MSVC Compiler, And then i was trying to link them, while compiling my OpenCV + Qt Project, using GCC.
    Then i’ve tried to compile OpenCV again using GCC. And…There is a bug. If anyone gets some problems with OpenCV 2.1 / gcc 4.5 compiling check these links out:
    http://tech.groups.yahoo.com/group/OpenCV/message/71034
    It works fine right now :).

  9. Hi,

    have you run across the problem that some opencv functions crash in QtCreator? It compiles and works fine but when it gets to some functions, like cv::HoughLinesP for example, it crashes for no apparent reason…

    • Andrew, you have to look at the message that opencv throws at you. Many opencv algorithms require the input images to be of a certain depth, have a specific number of channels or have a certain size.
      You have to look into the documentation of HoughLinesP and check the requirements on the inputs.

      Also, if your program crasher for no apparent reason, chances are it’s a pointer problem. You’re probably passing a NULL pointer when the opencv function requires an initialized pointer.

      If you look here: http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_ImageProcessing.htm#decl_cvHoughLines, you can see that it requires the line storage argument to be a CvMat* of a particular type, which means that it has to be initialized already.

      Good luck, and let me know if you get it working.

      I’ll be posting a line example very soon, so you can check back if you want.

      • Hey, well I just figured out what the problem was…

        Turns out that because I had VS2005 installed before (or at the same time as) VS2008, the LIB and INCLUDE paths in the Build Environment were pointing to the 2005 versions and also the Toolchain for the Qt version was using the 2005 compiler… but the Qt version I’m using is build with VS2008. So I changed everything to 2008 and it works fine.

        thanks for the quick reply though.

        Cheers,
        Andrew

  10. Hello everyone!

    I want use OpenCV2.1 with QtCreator on Windows XP, but there is a problem..

    mingw32-make[1]: Leaving directory `C:/Qt/2010.05/qt/vision-build-desktop’

    tmp/obj/debug_shared/mainwindow.o:c:/OpenCV2.1/include/opencv/cxmat.hpp:378: undefined reference to `cv::fastFree(void*)’

    collect2: ld returned 1 exit status

    mingw32-make[1]: *** [debug\vision.exe] Error 1

    mingw32-make: Leaving directory `C:/Qt/2010.05/qt/vision-build-desktop’

    mingw32-make: *** [debug-all] Error 2

    The process “C:/Qt/2010.05/mingw/bin/mingw32-make.exe” exited with code %2.
    Error while building project vision (target: Desktop)
    When executing build step ‘Make’

    My .pro is:
    INCLUDEPATH += C:\OpenCV2.1\include\opencv\

    LIBS += C:\OpenCV2.1\lib\cv210.lib \
    C:\OpenCV2.1\lib\cvaux210.lib \
    C:\OpenCV2.1\lib\cxcore210.lib\
    C:\OpenCV2.1\lib\cxts210.lib \
    C:\OpenCV2.1\lib\highgui210.lib \
    C:\OpenCV2.1\lib\ml210.lib

    Please! I need help!

    • Rastru, it sounds to me like it’s not linking to the correct libraries or dlls.

      Had you already installed an earlier version of opencv before?

      If yes, then make sure to delete the path to the earlier opencv dlls, or if you had copied the earlier opencv dlls into the windows system32 directory, make sure that you delete those and copy the new ones.

      Let me know how it works out.

  11. I was able to successfully link opencv and qt. Thx. My problem is how to convert Qimage to IplImage and vice versa. Could you please help me?

    • Nadeeshani, it is really easy to convert a QImage to an IplImage, I’ll probably put up a quick post on how to do it.

      But for now, you can have a look at the QImage structure. You’ll see that it’s very close to IplImage.

  12. Hi Navyenzo
    First of all, let me thank you for your quck steps to start an openCV project with QT and thank you the nice replies that you made for the queries. I followed the steps and I could made it working properly for a few programs. But now I have a problem. I could successfully build the following program, but when I tries to run it, a message box pops up saying that, “The application myprojectname.exe crashed, would you like to debug it.” Please help me to resolve this issue. Thank you once again.

    #include <QtCore/QCoreApplication>
    #include <cv.h>
    #include <highgui.h>
    #include <stdio.h>
    #include <string.h>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    CvCapture *capture = cvCaptureFromFile(“C:\\OpenCV2.2\\samples\\cpp\\Qt_sample\\cube4.avi”);
    cvReleaseCapture(&capture);
    return a.exec();
    }

    • No problem. It sounds to me that your program is probably not loading the avi file.

      Before you call cvReleaseCapture, make sure to check if The capture device actually loaded the avi file as follows:

      int main(int argc, char *argv[])
      {
          CvCapture* AVIfile = NULL;
          cvCaptureFromFile("C:/OpenCV2.2/samples/cpp/Qt_sample/cube4.avi");
          
          if(!AVIfile)
          {
              // Error -- We failed to load
              //          the AVI file
              return 1;
          }
          
          // By now we know the file loaded
          cvReleaseCapture(&AVIfile);
      }
      

      I recommend you download my blImageAPI, it will make your life much easier.

      Good luck!!!

  13. Hi Navyenzo,
            Thank you for your quick reply. I did exactly what you had told. But the same problem with the same error message persists. When I continued debugging by setting break points. It shows some assmbly code dumbs and pops up a message box immediately when the CVCapture method is invoked and tells that “Inferior stopped beacuse it received a signal from the operating system. Signal Name: SIGSEGV. Signal Meaning: Segmentation Fault. My .Pro file is
    #————————————————-
    #
    # Project created by QtCreator 2010-12-28T17:55:35
    #
    #————————————————-
    QT += core
    QT -= gui
    TARGET = Dec28C1
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    INCLUDEPATH += C:\OpenCV2.2\include\opencv C:\OpenCV2.2\include
    LIBS += C:\OpenCV2.2\lib\*.lib

    I have also tried by specifying each lib files. Am I missing some lib files additionally.
    Thank you.

    • Gopakumar, I have seen this type of problem before. And the main cause is that the program could not find the dlls needed to run it.
      Make sure that you have the opencv dlls in the correct directory.

      Either, copy the dlls in the windows system32 directory, or keep them in the directory of the executable where you’re running the program.

      Note: The directory of the executable changes if you’re running the program from the IDE or by double clicking it in windows.

      Also, make sure that if you had installed opencv before, that you don’t have a bunch of copies of your dlls, or a bunch of different paths for you dlls in windows. It could cause problems if you have an older version of opencv dlls and a newer one installed on the same computer.

      Let us know how that works out.

  14. Hi Enzo,         Sorry for the late reply. I didn\’t have internet access in my hostel. I had put the libraries in system32. but didn\’t work out. Since I can do almost all image processing work without any problem, but could not access the CVCapture, the video relating functions, it seems, it may be something other than this. Anyway yesterday, I did install it in ubuntu, and it works fine for me. But I have to resolve this issue on windows, as I have to work on windows here.

    • Don’t worry about it. But as a last resort, if I were you, I would delete all instances of OpenCV on your computer, (delete all dlls), everywhere, and the paths created by opencv to point to its dlls. Then download the latest opencv and let it install, and then try after a fresh restart.

      Once you figure it out, let us know what the problem was. Good luck.

  15. Pingback: Using OpenCV 2.2 within QTCreator in Windows | BarbatoLabs

  16. Thanks a lot for the article Mr.Enzo.. I’m working on my final project using Qt Creator and OpenCV2.2..My final project is to create a software for Video capturing via webcam, compress it, then send it through WLAN.. maybe you can give me some advice ? thank you

  17. I still have the message even following your 2 solutions , I dont know why?

  18. I still have the same message ”exited with code – 1073741515″even following your 2 solutions , I dont know why?

    • jose, the only reason you could be getting that message is because your program is not finding the appropriate dlls.

      Are you only using the OpenCV library? If that’s the case, and you let the setup set the path and restarted, and it still doesn’t work, then copy the dlls that come with the install and copy them into your system32 directory. (Copy them into the SYSWOW64 directory if in windows 64 bit).

      If you’re also using other libraries, which rely on dlls, you have to make sure that those dlls are either in the executable directory or the appropriate system32 or SYSWOW64 directories as I mentioned above.

  19. Firstly , I install my OpenCV via **.exe but not a library, Secondly I have already tried to put the DLL in the System32 but no effect,  I dont know more the problem. Help me please

  20. This is the code in ****pro
    #————————————————-
    #
    # Project created by QtCreator 2011-05-10T09:36:22
    #
    #————————————————-
    TARGET = openCV
    TEMPLATE = app
    INCLUDEPATH += C:\OpenCV2.2\include
    CONFIG(release,debug|release){
    LIBS += C:\OpenCV2.2\lib\opencv_calib3d220.lib \
    C:\OpenCV2.2\lib\opencv_contrib220.lib \
    C:\OpenCV2.2\lib\opencv_core220.lib \
    C:\OpenCV2.2\lib\opencv_features2d220.lib \
    C:\OpenCV2.2\lib\opencv_ffmpeg220.lib \
    C:\OpenCV2.2\lib\opencv_flann220.lib \
    C:\OpenCV2.2\lib\opencv_gpu220.lib \
    C:\OpenCV2.2\lib\opencv_highgui220.lib \
    C:\OpenCV2.2\lib\opencv_imgproc220.lib \
    C:\OpenCV2.2\lib\opencv_legacy220.lib \
    C:\OpenCV2.2\lib\opencv_ml220.lib \
    C:\OpenCV2.2\lib\opencv_objdetect220.lib \
    C:\OpenCV2.2\lib\opencv_ts220.lib \
    C:\OpenCV2.2\lib\opencv_video220.lib \
    }
    CONFIG(debug,debug|release){
    LIBS += C:\OpenCV2.2\lib\opencv_calib3d220d.lib \
    C:\OpenCV2.2\lib\opencv_contrib220d.lib \
    C:\OpenCV2.2\lib\opencv_core220d.lib \
    C:\OpenCV2.2\lib\opencv_features2d220d.lib \
    C:\OpenCV2.2\lib\opencv_ffmpeg220d.lib \
    C:\OpenCV2.2\lib\opencv_flann220d.lib \
    C:\OpenCV2.2\lib\opencv_gpu220d.lib \
    C:\OpenCV2.2\lib\opencv_highgui220d.lib \
    C:\OpenCV2.2\lib\opencv_imgproc220d.lib \
    C:\OpenCV2.2\lib\opencv_legacy220d.lib \
    C:\OpenCV2.2\lib\opencv_ml220d.lib \
    C:\OpenCV2.2\lib\opencv_objdetect220d.lib \
    C:\OpenCV2.2\lib\opencv_ts220.lib \
    C:\OpenCV2.2\lib\opencv_video220d.lib \
    }
    SOURCES += main.cpp\
    widget.cpp
    HEADERS += widget.h
    FORMS += widget.ui
     

    • jose, it looks as though the debug version of opencv 2.2 is the one giving problems, not the release version. There are some dependencies on microsoft shared libraries. I’m currently downloading and installing the visual express c++. Supposedly that downloads all the missing dlls. I’ll let you know if that’s the case.

      But again, the release version works out of the box

    • jose, it’s official, I downloaded the visual c++ express from the microsoft site, and it installed all the needed shared libraries for the opencv “debug” mode to work.

      Once again, the “release” version of opencv works out of the box, but the “debug” version of opencv libraries have some dependencies, which are solved when installing visual c++ express.

  21. Pingback: Build OpenCV with Qt Creator on Windows | Vic's World

  22. Pingback: Using OpenCV 2.3 with QTCreator in Windows | BarbatoLabs

  23. Hi,Thanks for your post but i encountered problem and my error in qt is
    1-in function ‘zn2cv3matD1Ev’:
    undefined refrence to ‘cv::fastFree(void*)’
    2-in function ‘ZN2cv3MatreleaseEv’:
    undefined refrence to ‘cv::Mat::deallocate()’
    3-error: ld returned 1 exist status
    —————————————————–
    this is my .pro
    INCLUDEPATH +=C:\OpenCV\release\install\include\
    LIBS +=-LC:\OpenCV\release\install\x64\\mingw\lib\
    -llibopencv_calib3d2410\
    -llibopencv_contrib2410\
    -llibopencv_core2410\
    -llibopencv_features2d2410\
    -llibopencv_flann2410\
    -llibopencv_highgui2410\
    -llibopencv_imgproc2410\
    -llibopencv_nonfree2410\
    -llibopencv_photo2410
    —————
    and my cpp code in qt is very simple:
    ————————————————-
    #include
    #include
    #include
    #include
    #include

    using namespace std;
    int main( )
    {
    cv::Mat saeed;
    cout<<"salam"<<endl;
    }
    ————————————
    i use qt 5.4(x86)
    and make opencv library with Cmake, mingw compiler

  24. Hi,Thanks for your post but i encountered problem and my error in qt is
    1-in function ‘zn2cv3matD1Ev’:
    undefined refrence to ‘cv::fastFree(void*)’
    2-in function ‘ZN2cv3MatreleaseEv’:
    undefined refrence to ‘cv::Mat::deallocate()’
    3-error: ld returned 1 exist status
    —————————————————–
    this is my .pro
    INCLUDEPATH +=C:\OpenCV\release\install\include\
    LIBS +=-LC:\OpenCV\release\install\x64\\mingw\lib\
    -llibopencv_calib3d2410\
    -llibopencv_contrib2410\
    -llibopencv_core2410\
    -llibopencv_features2d2410\
    -llibopencv_flann2410\
    -llibopencv_highgui2410\
    -llibopencv_imgproc2410\
    -llibopencv_nonfree2410\
    -llibopencv_photo2410
    —————
    and my cpp code in qt is very simple:
    ————————————————-
    #include
    #include
    #include
    #include
    #include

    using namespace std;
    int main( )
    {
    cv::Mat saeed;
    cout<<"Hi"<<endl;
    }
    ————————————
    i use qt 5.4(x86)
    and make opencv library with Cmake, mingw compiler

  25. is night sweat one of the atrioza’s side effects?

Leave a Reply

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