DEV Community

loading...
Cover image for Installing OpenCV on Windows for C++

Installing OpenCV on Windows for C++

Asmit Malakannawar
I'm a B.Tech Computer Science and Business Systems student. I am a Cloud Enthusiast and a learner, and deeply passionate about Software Development & Innovations.
Updated on ・2 min read

Screenshot (59)

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

Screenshot (60)

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

    Set the platform target to x64

Screenshot (50)

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

Screenshot (51)

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

Screenshot (53)

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

Screenshot (55)

  • 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.

Screenshot (56)

  • 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);
        } 
    } 
Enter fullscreen mode Exit fullscreen mode
  • Your Output Screen should display your live Web-Cam feed.

Screenshot (61)

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

For more install information, visit the OpenCV official guide.

Discussion (0)