Tutorial: OpenCV v4.2.0 Installation in Windows 10

Install OpenCV and Run a Demo Program

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.

--

--

--

PhD, Researcher. I share what I've learnt and done. :) My LinkedIn: https://www.linkedin.com/in/sh-tsang/, My Paper Reading List: https://bit.ly/33TDhxG

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sik-Ho Tsang

Sik-Ho Tsang

PhD, Researcher. I share what I've learnt and done. :) My LinkedIn: https://www.linkedin.com/in/sh-tsang/, My Paper Reading List: https://bit.ly/33TDhxG

More from Medium

Jump start in object detection with Detectron2 (license plate detection)

Multi-gesture detection with Tensorflow API ‘TFOD’

TFOD : Object Detection with Tensorflow Object Detection API

Solving Mazes with Tensor Flow and OpenCV