Install and configure OpenCV-4.2.0 in Windows 10 — VC++

Complete guide to install OpenCV-4.2.0 in Windows 10

Aymane Hachcham
Towards Data Science

--

This post will guide you through all the steps for installing and configuring OpenCV-4.2.0 in Windows 10 (64-bit) within 2 different environments:

  • OpenCV with Visual Studio 2019, for C++ development
  • OpenCV with Anaconda, for Python 3.6.0+ development

I will focus here on OpenCV for Visual Studio with C++, the other tutorial part for python and Anaconda can be found here.

Note: To follow along with the tutorial, I will assume that you already have Visual Studio 2019 installed. If not, please feel free to install these tools before continuing to read further.

OpenCV-4.2.0 for Visual Studio 2019

All the required steps for setting up OpenCV for a Visual C++ development.

Step1: Install the C++ Desktop development Workload

Open your Visual Studio Installer tool and add C++ for desktop development as a workload to your current Visual Studio IDE version. This step is essential since you can not use OpenCV in VS without all the C++ required libraries.

Visual Studio Installer Wizard

Step 2: Download and Install OpenCV-4.2.0

Download OpenCV 4.2.0 latest stable release (opencv-4.2.0-vc14_vc15.exe) for Windows platform. Go to the official OpenCV website: https://opencv.org/ -> Resources -> Releases and click on the Windows platform. You will be redirected to SourceForge and download will automatically start.

OpenCV-4.2.0 releases: https://opencv.org/releases/

Before running the download .exe file, go to your C:\ folder and add a new folder named opencv-4.2.0. Run the installer and extract the zip file to the opencv-4.2.0 folder newly created.

Extract the zip file containing the builds for OpenCV to your folder

Step 3: Add OpenCV binaries to your System path

Once OpenCV is correctly installed in your folder, you now have to add the binaries C:\OpenCV-4.2.0\opencv\build\x64\vc15\bin to your system path, so you can have access to OpenCV executables easily through your command line.

Editing the system path

Step 4: Configure a Visual Studio project to run OpenCV

Open Visual Studio 2019, choose to create a new project and go for the C++ Console App template.

Create a new project, and choose Console App C++ template

Once the project created you should have a layout with a solution explorer to the right having one source file and in the window upper ribbon you should see Debug for x86 platforms, meaning that the project will build and run in debug mode targeting x86 windows architectures.

  • First, you should change the solution platforms from x86 to x64
  • Secondly, you have to change the Project Properties to add the OpenCV libraries
Change the target solution platform, and head to project properties

There are a bunch of properties to edit before being able to execute any code:

  1. Go to Configuration Properties/VC++ Directories to add the include and library directories for OpenCV.
Edit both Include and Library Directories
Click on the right arrow next to blue entry
Include the internal system path

For the Include directory, you have to add the following path: C:\OpenCV-4.2.0\opencv\build\include. Do the same for the Library Directories adding this internal path: C:\OpenCV-4.2.0\opencv\build\x64\vc15\lib.

Include and Lib directories both added to the project

2. Edit the VC++ project linker with the opencv_world420d.lib OpenCV dynamic library. You will find the DLL (Dynamic Link Library) here: C:\OpenCV-4.2.0\opencv\build\x64\vc15\lib copy the name of the file opencv_world420d.lib and paste it in the dependency box.

Click the OK button when finished

Final Step: Test a bit of code

Finally, you can run this demo code in your visual studio IDE to see if it’s all working fine.

The resulting image

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

For more install information, visit the OpenCV official guide.

--

--