How to Install OpenCV and Qt Creator on Windows with 64 bit MinGW

In the earlier post we configured codeblocks with opencv. However, If you are looking for more advanced GUI application then you should go for QT library. QT provides excellent easy to use front end framework with their super fast visual editor qt creator.

In this post we will configure qt creator and opencv.

Required software:

  1. OpenCV: Download OpenCV pre-built for windows. As said earlier we are not going to use those binaries instead we will make our own. (those pre-built binary sucks most of the time). extract it to C:\ You will find two folder there: ‘build’ and ‘sources’.
  2. QT Library (5.3.1): Don’t know why official website doesn’t provide 64 bit MinGW version of QT. However, you can find 64 bit mingw here. Install it in C:\Qt
  3. Qt Creator (3.2.0): Download and install 64 bit form here and install it in C:\Qt
  4. MinGW 64: MinGw 64bit is already installed with Qt library. You can see it in C:\Qt\qt-5.3.1-x64-mingw482r4-sjlj\mingw64
  5. Path Editor: Download a handy tiny path editor tool from here.
  6. CMake: Download Cmake from here. install it in C:\.

Procedure:

  1. Open path editor and set the following two folder into system variable. C:\Qt\qt-5.3.1-x64-mingw482r4-sjlj\mingw64\bin”
    C:\CMake\bin
  2. Open cmake, set source path to C:\opencv\sources and binary path to C:\opencv-mingw. [make a folder in C:\ called “opencv-mingw”]cmake
  3. Hit configure button. A pop up window will open and the from drop-down menu select ‘MinGW Makefiles’ and press next. There you have to select c and c++ compilers which would be found in bin folder of mingw. If you are trying opencv 3.0 alpha then just deselect IPP option. And finally press generate button.cmake1cmake2
  4. Now open command prompt go to C:\opencv-mingw. Type:               mingw32make mingw-make
  5.  now type: mingw32make installinstall

And you are Done ! You have successfully built copencv! Now it is time to configure qt creator with opencv library.

Run qt creator and create a new qt widget application, give it a name “opencv”.

  1. Add these lines in opencv.pro file:                                                    INCLUDEPATH += C:\opencv-mingw\install\include
    LIBS += -L”C:/opencv-mingw/install/x64/mingw/bin”
    LIBS += -lopencv_core249 -lopencv_highgui249 -lopencv_imgproc249
  2. add the following lines in main() function:
    cv::Mat image= cv::imread(“pic.jpg”);
    cv::namedWindow(“Tulips”);
    cv::imshow(“Tulips”, image);
    cv::waitKey(1000);
  3. Dont forget to put a picture called pic.jpg in project folder !

Now run the program 🙂

Advertisements

27 thoughts on “How to Install OpenCV and Qt Creator on Windows with 64 bit MinGW

  1. hello
    tried it on ver qt-5.3.2-x64-mingw491r1-sjlj
    used the following path for the C compiler
    C:/Qt/qt-5.3.2-x64-mingw491r1-sjlj/mingw64/bin/gcc.exe
    and the following path for C++
    C:/Qt/qt-5.3.2-x64-mingw491r1-sjlj/mingw64/bin/g++.exe

    after click the finish button went to
    command prompt
    and use the following line: mingw32-make and got the following massage
    ” NO targets specified and no makefile found”
    please can you help me solve it?
    many thanks
    TP

  2. I got to the point where you said, “There you have to select c and c++ compilers which would be found in bin folder of mingw. And finally press generate button.”
    Don’t see what you’re talking about. I pressed Generate and it did so, but I do not know if it prepared Qt to function!!

  3. Thank you very much for such a nice description, it is very helpful. But could you please explain a bit more detailed what does cmake do and this command: mingw32-make install . Please sorry for such a silly questions, I am a newbie in CPP progrramming 🙂

  4. I followed your instructions but when I want create a new qt widget application in Qt. I get an error saying that “No valid kits found”.

    Do you know what cause this and how can I solve it? I have been trying to install Qt and openCv for so long. Yours was the one I could proceed smoothly but couldn’t complete 😦

    Thanks

    • I showed the qmake file now it is building

      But I am having problems to link opencv library. I tried to run the process again and when I type mingw32-make in command window I am getting the following error


      [ 71%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_
      core.cpp.obj
      C:/Qt/qt-5.4.0-x64-mingw492r0-sjlj/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9
      .2/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\opencv_perf_gpu.dir\per
      f\perf_core.cpp.obj: too many sections (33014)
      C:\Users\TEC-ECN\AppData\Local\Temp\ccxk96Lm.s: Assembler messages:
      C:\Users\TEC-ECN\AppData\Local\Temp\ccxk96Lm.s: Fatal error: can’t write CMakeFi
      les\opencv_perf_gpu.dir\perf\perf_core.cpp.obj: File too big
      C:/Qt/qt-5.4.0-x64-mingw492r0-sjlj/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9
      .2/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\opencv_perf_gpu.dir\per
      f\perf_core.cpp.obj: too many sections (33014)
      C:\Users\TEC-ECN\AppData\Local\Temp\ccxk96Lm.s: Fatal error: can’t close CMakeFi
      les\opencv_perf_gpu.dir\perf\perf_core.cpp.obj: File too big
      modules\gpu\CMakeFiles\opencv_perf_gpu.dir\build.make:78: recipe for target ‘mod
      ules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_core.cpp.obj’ failed
      mingw32-make[2]: *** [modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_core.
      cpp.obj] Error 1
      CMakeFiles\Makefile2:4882: recipe for target ‘modules/gpu/CMakeFiles/opencv_perf
      _gpu.dir/all’ failed
      mingw32-make[1]: *** [modules/gpu/CMakeFiles/opencv_perf_gpu.dir/all] Error 2
      makefile:136: recipe for target ‘all’ failed
      mingw32-make: *** [all] Error 2

      C:\opencv-mingw>

  5. Somehow my generated opencv-mingw folder doen not have an install sub-dir…. when using the prebuild libraries the QT Creator does not understand what ‘cv’ is, after including is gives me the error that it cannot find cv.h while in opencv.pro the include path is correct…. stuck…

  6. Hi, Mr Hasan;
    I followed all the steps instalation and everything is fine, except when I get to step 4, in the command window, it Boque and I have the following error:

    [31%] Linking CXX shared library .. \ .. \ bin \ libopencv_core300.dll
    C: / Qt / Tools / mingw491_32 / bin /../ lib / gcc / i686-mingw32-w64 / i686 4.9.1 /../../../../-w
    64-mingw32 / bin / ld.exe: can not find -lRunTmChk
    collect2.exe: error: ld returned 1 exit status
    modules \ core \ CMakeFiles \ opencv_core.dir \ build.make 1286: recipe for target ‘bin /
    libopencv_core300.dll ‘failed
    mingw32-make [2]: *** [bin / libopencv_core300.dll] Error 1
    CMakeFiles \ Makefile2: 1654 recipe for target ‘modules / core / CMakeFiles / opencv_cor
    e.dir / all ‘failed
    mingw32-make [1]: *** [modules / core / CMakeFiles / opencv_core.dir / all] Error 2
    Makefile: 148: recipe for target ‘all’ failed
    mingw32-make: *** [all] Error 2

    C: \ release>

    Can you tell me why ?

    Thankss

    • After you complate the configuration step, you should see some red lines. You need to change their location to let cmake access them. E.g for “Opengl” line you need to change the adress like : C:\Qt\qt-5.5.0-x64-mingw510r0-seh-rev0\qt-5.5.0-x64-mingw510r0-seh-rev0\lib\cmake\Qt5OpenGL (it is my folder direction, you need to specify the correct direction according to your setup path.)

  7. OpenCV 3 doesn't seem to work with Qt - BlogoSfera

  8. Visual Studio 2015 编译支持 QT5 的 OpenCV3库 « Technology makes this world impressive!

  9. Visual Studio 2015 编译支持 QT5 的 OpenCV3库 « Technology makes this world impressive!

  10. Visual Studio 2015 编译支持 QT5 的 OpenCV3库 – Technology make this world impressive!

  11. I have this problem in command prompt
    Linking CXX shared library ..\..\bin\libopencv_imgproc249.dll
    [ 23%] Built target opencv_imgproc
    mingw32-make[2]: *** No rule to make target ‘C:/opencv-2.4.9 source/sources/modules/highgui/’, n
    eeded by ‘modules/highgui/qrc_window_QT.cpp’. Stop.
    CMakeFiles\Makefile2:2029: recipe for target ‘modules/highgui/CMakeFiles/opencv_highgui.dir/all’
    failed
    mingw32-make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    makefile:135: recipe for target ‘all’ failed
    mingw32-make: *** [all] Error 2

    please some body tell me how can i fix it .

  12. i am using opencv3.1 version.
    I add following code in my .pro file of QT creator.

    INCLUDEPATH += C:\OpenCV310\mybuild\install\include
    LIBS += -L”C:/OpenCV310/mybuild/install/x64/mingw/bin”
    LIBS += -lopencv_core310 -lopencv_highgui310 -lopencv_imgproc310

    but i get this error.
    LINK : fatal error LNK1104: cannot open file ‘opencv_core310.lib’

    in directory “C:\OpenCV310\mybuild\install\x64\mingw\bin”, these are only dll files, like libopencv_core310.dll and not a .lib files.

    How to solve this problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s