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
- Download & Install OpenCV
- Run a Demo Program Using Visual Studio with Proper Settings
1. Download & Install OpenCV & Setup Environmental Variable
1.1. Download
- Go to https://opencv.org/releases/.
- Click “Windows” to download the package.
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.
Reference
Sample Codes from:
https://medium.com/@subwaymatch/adding-opencv-4-2-0-to-visual-studio-2019-project-in-windows-using-pre-built-binaries-93a851ed6141
My Previous Tutorials
Linux [Ubuntu Installation] [NVIDIA Driver Installation (2018) (Old)] [OpenSSH Installation] [Hard Drive Partitioning/Formatting/Mounting] [Add 1 More GPU] [TeamViewer Installation][NVIDIA Driver Installation (2019)]
Windows [Anaconda + Spyder + TensorFlow 2.0 @ Windows 10] [OpenCV v4.2.0 Installation in Windows 10]
Docker [Docker Installation] [Pulling Image] [Running Image] [Exporting/Saving Image] [Nvidia-Docker 2.0 Installation]
Caffe [Image Classification] [Handwritten Digit Classification] [Style Recognition]
Video Coding [Generate VTM Solution (2019) (Old)] [Generate HM+360 Solution] [Generate VTM+360 Solution] [Generate VTM Solution (2020)]