Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Using opencv3.1 with Qt5.5 in Windows 10

    General and Desktop
    6
    20
    12858
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • brotify
      brotify last edited by

      I want to use opencv-3.1 with Qt 5.5 on Windows 10. I read and watched lots of different tutorials but I could not set up it. Actually most of them was for previous version of opencv and qt. Everytime I got problems. Can anyone show me how to setup opencv step by step. Thanks in advance.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        What do you mean by "setup OpenCV" ? Build it ? Use it in your Qt project ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        brotify 1 Reply Last reply Reply Quote 0
        • brotify
          brotify @SGaist last edited by brotify

          @SGaist Using it in qt project.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            What exact problem do you have currently ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • brotify
              brotify last edited by brotify

              Ok let me say what I did so far;

              1. First I extracted opencv3.1 to directory C:\opencv2. Therefore initially there was two folders in this directory namely "source" and "build". Then I created a new folder named "release".
              2. To build libraries I used C make 3.4.3. I selected "C:/opencv2/sources" as a source directory and selected "C:/opencv2/release" to build binaries.
              3. I clicked "Configure" and selected "MinGW Makefiles" as generetor and selected "Specify native compilers". Then I selected "C:/Qt/Tools/mingw491_32/bin/gcc.exe" as the C compiler and "C:/Qt/Tools/mingw491_32/bin/g++.exe" as the C++ compiler. (By the way I am using Qt 5.4)
              4. I did not change any other options and clicked configure till all red lines disappear. Next I clicked "generate" and closed Cmake gui.

              5)Then I opened CMD window I opened the directory C:\opencv2\release and I typed "mingw32-make", it took about 30 minutes. Then I typed "mingw32-make install" .

              System variables that I added is shown in the picture.
              http://i.hizliresim.com/v5LnJr.png

              6)Then I created Qt console application and I added these to .pro file

              INCLUDEPATH += C:\opencv2\release\install\include
              LIBS += -LC:\\opencv2\\release\\install\\x86\\mingw\\bin\
                  libopencv_core310 \
                  libopencv_highgui310 \
                  libopencv_imgproc310 \
                  libopencv_features2d310 \
                  libopencv_calib3d310 \
              Then I clicked "run qmake"
              

              In the source file

              #include <QCoreApplication>
              #include <opencv2/opencv.hpp>
              int main(int argc, char *argv[])
              {
                  QCoreApplication a(argc, argv);
               
              
                  return a.exec();
              }
              

              But I get the error,
              error: LNK1104: cannot open file 'libopencv_core310.obj'

              jsulm 1 Reply Last reply Reply Quote 0
              • mrdebug
                mrdebug last edited by

                Hi. You have to build OpenCV with MinGW only if you want to use Qt on Windows builded with MinGW.
                The OpenCV package already has the vs libraries.
                Anyway which are your cmake switches?

                Need programmers to hire?
                www.labcsp.com
                www.denisgottardello.it
                GMT+1
                Skype: mrdebug

                brotify 1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @brotify last edited by

                  @brotify This should be changed:

                  LIBS += -LC:\\opencv2\\release\\install\\x86\\mingw\\bin\
                      libopencv_core310 \
                      libopencv_highgui310 \
                      libopencv_imgproc310 \
                      libopencv_features2d310 \
                      libopencv_calib3d310 \
                  

                  to:

                  LIBS += -LC:/opencv2/release/install/x86/mingw/bin\
                      -lopencv_core310 \
                      -lopencv_highgui310 \
                      -lopencv_imgproc310 \
                      -lopencv_features2d310 \
                      -lopencv_calib3d310 \
                  

                  In pro files you should use forward slashes in paths and not back slashes (even on Windows).
                  Are the libraries directly in C:\opencv2\release\install\x86\mingw\bin?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  brotify 1 Reply Last reply Reply Quote 0
                  • brotify
                    brotify @jsulm last edited by

                    @jsulm

                    INCLUDEPATH += C:\opencv2\release\install\include
                    LIBS += -LC:/opencv2/release/install/x86/mingw/bin\
                        -lopencv_core310 \
                        -lopencv_highgui310 \
                        -lopencv_imgproc310 \
                        -lopencv_features2d310 \
                        -lopencv_calib3d310 \
                    
                    INCLUDEPATH += C:/opencv2/release/install/include
                    LIBS += -LC:/opencv2/release/install/x86/mingw/bin\
                        -lopencv_core310 \
                        -lopencv_highgui310 \
                        -lopencv_imgproc310 \
                        -lopencv_features2d310 \
                        -lopencv_calib3d310 \
                    

                    I tried both of them but this time I get this error:
                    LNK1104: cannot open file 'opencv_core310.lib'

                    Let me show the screenshot of what is inside "C:\opencv2\release\install\x86\mingw\bin"
                    http://i.hizliresim.com/0nkDAY.png

                    jsulm 1 Reply Last reply Reply Quote 0
                    • brotify
                      brotify @mrdebug last edited by brotify

                      @mrdebug
                      I have to say that I am not experienced developer. Therefore I did not fully understand what are saying. I used Mingw because in the tutorials thay were using Cmake and Mingw. If there are another method to use opencv in Qt project, it will be good to me to know.

                      1 Reply Last reply Reply Quote 0
                      • mrdebug
                        mrdebug last edited by

                        Sorry but all the tutorials that I have tried in order to to use OpenCV in all platforms are not perfectly usable. To setup OpenCV with Qt is more difficult than to write a OpenCV program.
                        To start: what qt version are you using? The Qt version based on mingw32 or the version based on vc?

                        Need programmers to hire?
                        www.labcsp.com
                        www.denisgottardello.it
                        GMT+1
                        Skype: mrdebug

                        brotify 1 Reply Last reply Reply Quote 0
                        • jsulm
                          jsulm Lifetime Qt Champion @brotify last edited by

                          @brotify Can you search for opencv_core310.lib (and other needed *.lib files) in the installation directory?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply Reply Quote 0
                          • A
                            asanka424 last edited by

                            It seems like you are trying to use OpenCV built using MinGW with Qt built with Visual Studio. There are two things you can do.

                            1. use OpenCV pre built. Which is in your build folder of OpenCV downloaded zip

                            2. change the kit in your Qt Creator to use MinGW build of Qt.

                            Hope this helps

                            brotify 1 Reply Last reply Reply Quote 0
                            • brotify
                              brotify @asanka424 last edited by brotify

                              Please note that I have solved my problem but I will not delete this post because it may help other people.
                              @asanka424
                              Thanks, I selected Mingw32 as the kit and it worked but this time I get a different error. I tried a simple opencv program which shows the image however it gives this error:
                              undefined reference to `cv::imread(cv::String const&, int)'

                              Here is my code,

                              #include <opencv2/core/core.hpp>
                              #include <opencv2/highgui/highgui.hpp>
                              #include <iostream>
                              
                              using namespace cv;
                              using namespace std;
                              
                              int main(  )
                              {
                              
                              
                                  Mat image;
                                  image = imread("img.jpg", CV_LOAD_IMAGE_COLOR);   
                              
                                  if(! image.data )                       
                                  {
                                      cout <<  "Could not open or find the image" << std::endl ;
                                      return -1;
                                  }
                              
                                  namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
                                  imshow( "Display window", image );             
                              
                                  waitKey(0);                                      
                                  return 0;
                              }
                              
                              

                              and here is my .pro file

                              QT += core
                              QT -= gui
                              
                              CONFIG += c++11
                              
                              TARGET = untitled
                              CONFIG += console
                              CONFIG -= app_bundle
                              
                              INCLUDEPATH += C:/opencv2/release/install/include
                              LIBS += -LC:/opencv2/release/install/x86/mingw/bin\
                                  -lopencv_core310 \
                                  -lopencv_highgui310 \
                                  -lopencv_imgproc310 \
                                  -lopencv_features2d310 \
                                  -lopencv_calib3d310 \
                              
                              
                              TEMPLATE = app
                              
                              SOURCES += main.cpp
                              

                              And lastly can you show me how to use first method that is using opencv pre-built?

                              1 Reply Last reply Reply Quote 0
                              • brotify
                                brotify @mrdebug last edited by brotify

                                @mrdebug
                                I was not aware of that Qt has two different versions. So far I was using VC. Now I am using MinGw and it seems that the problem was this. Yet I have another problem which I posted before this post.

                                1 Reply Last reply Reply Quote 0
                                • brotify
                                  brotify last edited by brotify

                                  Ok, I want to thanks all of you who tried to help me. Hopefully I solved my problem. I solved the last problem by adding to .pro file

                                  LIBS += "C:\opencv2\release\lib\libopencv_imgcodecs310.dll.a"
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • B
                                    beginMyCoding last edited by

                                    Hello
                                    I am also in a same situation, i did not find any solution till now.
                                    I am using Qt creator 5.5 with mingw492_32 and openCv 3.10 with VC.
                                    When i try to write a small code to read the image matrix using cv::imread() it gives me error.

                                    error: undefined reference to `cv::imread(cv::String const&, int)
                                    

                                    this is my

                                    test.pro

                                    QT       += core gui
                                    
                                    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                                    
                                    TARGET = Test
                                    TEMPLATE = app
                                    
                                    
                                    SOURCES += main.cpp\
                                            mainwindow.cpp
                                    
                                    HEADERS  += mainwindow.h
                                    
                                    FORMS    += mainwindow.ui
                                    
                                    INCLUDEPATH += LC:\opencv\build\include
                                    
                                            LIBS += C:\opencv\build\x64\vc14\lib\opencv_world310.lib \
                                                    C:\opencv\build\bin\opencv_ffmpeg310.dll
                                    

                                    i have only one library file in the openCV folder
                                    Do you have any idea what i am suppose to do?

                                    1 Reply Last reply Reply Quote 0
                                    • mrdebug
                                      mrdebug last edited by

                                      Hi.
                                      You can't use the vc libraries of OpenCV with Qt built with Mingw. If you want to use Qt with mingw you have to build OpenCV with Mingw.
                                      I confirm Qt 5.5 works perfectly with OpenCV 3.
                                      http://www.denisgottardello.it/ComputerVisionStudio/index.php

                                      Need programmers to hire?
                                      www.labcsp.com
                                      www.denisgottardello.it
                                      GMT+1
                                      Skype: mrdebug

                                      1 Reply Last reply Reply Quote 0
                                      • B
                                        beginMyCoding last edited by

                                        Is there any link which explains perfect installation of OpenCV 3 and Qt5.5?

                                        1 Reply Last reply Reply Quote 0
                                        • mrdebug
                                          mrdebug last edited by

                                          These lines of code work perfectly with Qt 5.5.0 and OpenCV 3.0
                                          set PATH=%PATH%;C:\Qt\Qt5.5.0\Tools\mingw492_32\bin;C:\Program Files (x86)\CMake 2.8\bin
                                          cmake -G "MinGW Makefiles" -DWITH_FFMPEG=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_videoio=ON -DWITH_IPP=OFF -DWITH_OPENCL=OFF -DWITH_JASPER=OFF -DWITH_OPENEXR=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_EXTRA_MODULES_PATH=modules/opencv_contrib-master/modules .

                                          mingw32-make -j 4

                                          I have only some problems with webcams in some 64 bit machines.

                                          Another hard problem is to setup the pro file. You have to include the libraries in a particular order (depends from your program). Some libraries can be included more than one time.
                                          This solution sounds to be very strange but I assure, to have OpenCV working I have spent a lot of time.

                                          If you need professional support please send me an email at info@denisgottardello.it

                                          Need programmers to hire?
                                          www.labcsp.com
                                          www.denisgottardello.it
                                          GMT+1
                                          Skype: mrdebug

                                          B 1 Reply Last reply Reply Quote 0
                                          • B
                                            beginMyCoding @mrdebug last edited by

                                            @mrdebug
                                            I seriously did not understand from 3rd line (cmake).

                                            I set the paths of Qt and CMake
                                            Below are my paths
                                            C:\Qt\5.5\mingw492_32\bin
                                            C:\CMake\bin

                                            I don't understand what I have to do in CMake?
                                            Can you say me any step by step procedure or any other way?

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post