Tutorial: OpenCV v4.2.0 Installation in Windows 10

Install OpenCV and Run a Demo Program

Sik-Ho Tsang
3 min readMar 13, 2020

In this story, I will download and install OpenCV v4.2.0 and run a demo program to confirm if OpenCV is successfully installed.

Outline

  1. Download & Install OpenCV
  2. Run a Demo Program Using Visual Studio with Proper Settings

1. Download & Install OpenCV & Setup Environmental Variable

1.1. Download

https://opencv.org/releases/

1.2. Install

  • Click the package to unpack the files.
  • I choose C: as my file location.
  • After that, there should be a folder C:\opencv.

1.3. Setup Environment Variable

  • Go to Settings for Windows 10.
  • Search “View Advanced System Settings”, and click it.
  • In the System Properties, click “Environment Variables…”.
  • At the System Variables, find & click “Path”, Click “Edit…”.
  • Click “New” to add a new path “C:\opencv\build\x64\vc15\bin” as shown above. Then Click OK to close all popup windows.

2. Run a Demo Program Using Visual Studio with Proper Settings

2.1. Create a New Project

  • Launch Visual Studio. I use VS2017, it should be similar for other versions including 2019.
  • Click “File > New > Project…”
  • Choose “Console App” to create a new project.
  • And I choose the “x64” platform for the program.

2.2. Project Properties Setup

  • In VC++ Directories, at Include Directories, add:
C:\opencv\build\include
  • Also, at Library Directories, add:
C:\opencv\build\x64\vc15\lib
  • In Linker > Input, at Additional Dependencies, for debug mode, add:
opencv_world420d.lib
  • For release mode, please add:
opencv_world420.lib

2.3. Test the Codes

  • Add the below sample codes:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image = Mat::zeros(300, 600, CV_8UC3);
circle(image, Point(250, 150), 100, Scalar(0, 255, 128), -100);
circle(image, Point(350, 150), 100, Scalar(255, 255, 255), -100);
imshow("Display Window", image);
waitKey(0);
return 0;
}
  • Run the code. The following should be shown which means OpenCV can be used.

--

--

Sik-Ho Tsang
Sik-Ho Tsang

Written by Sik-Ho Tsang

PhD, Researcher. I share what I learn. :) Linktree: https://linktr.ee/shtsang for Twitter, LinkedIn, etc.

No responses yet