OpenCV integration with Visual Studio and QT

Untitled

In the previous tutorial, we installed OpenCV on Windows. In this tutorial, we’ll see how to compile your C++ programs with Visual Studio. We are using Qt 5.4.0 (MSVC 2013, 32-bit) and Visual Studio 2013 (32-bit) version for compiling OpenCV 3.0.0 C++ code in a Windows 10 64-bit machine but the same method should work for other versions of the respective software bundles. So, lets get started.

Integration with Visual Studio

  1. To create a new Visual Studio Project, open Visual Studio -> New Project -> Visual C++ -> Win32 Console Application. Click OK. Then click Next -> Finish.
    Untitled
    This will create a New C++ project. Now, we just have to integrate it with OpenCV.
  2. Now, in the top menu of your /visual Studio, Click on PROJECT >> Properties.
    Untitled
  3. Go to C/C++ >> General >> Additional Include Directories and add your OpenCV’s include directory.
    zz
    For e.g.:

    C:\opencv\build\install\include\opencv;C:\opencv\build\install\include;

  4. Go to Linker -> General -> Additional Library Directories. Add your libraries path over there
    zz
    For e.g.:

    C:\opencv\build\install\x86\vc12\lib;

  5. Next, go to Linker -> Input -> Additional Dependencies. 
    zzAdd the following dependencies to it:

    opencv_calib3d300d.lib
    opencv_core300d.lib
    opencv_features2d300d.lib
    opencv_flann300d.lib
    opencv_highgui300d.lib
    opencv_imgcodecs300d.lib
    opencv_imgproc300d.lib
    opencv_ml300d.lib
    opencv_objdetect300d.lib
    opencv_photo300d.lib
    opencv_shape300d.lib
    opencv_stitching300d.lib
    opencv_superres300d.lib
    opencv_ts300d.lib
    opencv_video300d.lib
    opencv_videoio300d.lib
    opencv_videostab300d.lib
    opencv_xfeatures2d300d.lib
    vcvc

    for Debug mode. If you want to add them for Release mode, just remove ‘d’ from each .lib file’s name and add.
    Note: Make sure all these lib files exist in your libraries directory defined in Step 3. Look out for the ‘d’ in each file name at the end.

Integration with Qt

Download Qt (32-bit) for your respective VS version from here and install it.

Note: Qt directory should not contain any spaces. So, I recommend to install it in C:\Qt directory.

Open Qt Creator and create a new Qt Widgets Application

zz

It will create many files. Double click on the .pro file and add the following code to it.

zz

INCLUDEPATH += C:/opencv/build_debug/install/include

Note: The INCLUDEPATH and the LIBS Path are the location of your OpenCV include directory and libs diretory respectively.

1 Comment

  1. VJ Sir

    nice tutorial

    Reply

Leave a Comment

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