Installing OpenCV on Windows for C++

Installing OpenCV on Windows for C++

OpenCV is a library of programming functions mainly aimed at real-time computer vision. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code.

Here are the simple installation guide to install OpenCV on Windows:

GitHub repo

  • Add bin folder to the Environment Variables path. For eg: C:\opencv\build\x64\vc15\bin

bin folder

  • Create a New Visual Studio project C++ console.

    Set the platform target to x64

new vs project

  • Add Directories by going to: Project->Properties->Configuration Properties-

Configuration Properties

**VC++ Directories**
1. Add Build Directories: `C:\opencv\build\include`
2. Add Library Directories: `C:\opencv\build\x64\vc15\lib`

VC++ Directories

**Linker Input** 
1. Add to Linker->Input: `opencv_world452d.lib` (`452` depends 
   on your OpenCV version)
   `d` for debug, without `d` for release 

Linker Input

  • Click on your Project name on right side in Solutions Explorer, and right-click on it to Add a New Item.

Select C++ File and rename it as test.cpp.

test.cpp

  • Finally, you can run this demo code in your visual studio IDE to see if it’s all working fine.
    #include <opencv2/imgcodecs.hpp>
    #include <opencv2/highgui.hpp>
    #include <opencv2/imgproc.hpp>
    #include <iostream>

    using namespace std;
    using namespace cv;

    void main() {

        VideoCapture cap(0);
        Mat img;

        while (true) {

            cap.read(img);
            imshow("Image", img);
            waitKey(1);
        } 
    }
  • Your Output Screen should display your live Web-Cam feed.

output

And that’s all, you can now use OpenCV with ease. 😉

For more install information, visit the OpenCV official guide.