Simple intro to OpenCV

I am presently experimenting with OpenCV (if didn’t know before OpenCV is a Computer Vision Library for Academic and Commercial use). This article is about OpenCV on windows 10 using Visual Studio 2015. I have tried my hand at various building and installation methods and this is the simplest way I have come by.

1. Get the latest release of the OpenCV at the website. URL link: and Download for windows (Win Pack).

2. After Downloading run the file and extract. I extracted to same place I ran the program from.

“opencv” folder gotten from extraction

3. Now you create a system environment variable named “OPENCV_DIR” with value “C:\<the location you extracted to>\opencv\build\x64\vc14″. My example is below.

4. Open your Visual Studio 2015 IDE. Create a new project, a Win32 Console Application (chose whatever name suits you). Ensure Radio Button and Check box are selected as below.

5. Add an Empty new .cpp file to the project. Then, go to View > Other Windows  and select Property Manager.

6. Make sure solution Configuration and Platform is set to Debug and x64 respectively.

7. Right Click on “Debug | x64” in the Property Manager and click on properties. a) Under the ” C/C++ > Additional Include Directories” add
“$(OPENCV_DIR)\..\..\include;” b) Under “Linker >
Additional Library Directories”
add “$(OPENCV_DIR)\ lib;” and c) Add “opencv_world401d.lib” under Linker > Input > Additional Dependencies. Click OK.

Note: The 401 in opencv_world401.lib represents the version number, make sure it match the library files you downloaded.


8. Copy and Paste the code below into your .cpp file.

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
    String imageName( "data/vulkan.png" ); // by default
    if( argc > 1)
        imageName = argv[1];
    Mat image;
    image = imread( imageName, IMREAD_COLOR ); // Read the file
    if( image.empty() )                      // Check for invalid input
        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 );                // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;

9. Before you run the code. Download and save picture at C:\Users\<Your User Name>\Documents\Visual Studio 2015\Projects\Intro OpenCV\Intro OpenCV\data. Link to picture here.

10. Now run and have fun.

Leave a comment

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