Install and configure OpenCV-4.2.0 in Windows 10 — VC++
Complete guide to install OpenCV-4.2.0 in Windows 10
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.
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.
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.
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.
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.
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
tox64
- Secondly, you have to change the Project Properties to add the OpenCV libraries
There are a bunch of properties to edit before being able to execute any code:
- Go to Configuration Properties/VC++ Directories to add the include and library directories for OpenCV.
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.
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.
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.
And that’s all, you can now use OpenCV with ease. 😉
For more install information, visit the OpenCV official guide.