Setting up OpenCV C++ on Windows Subsystem for Linux (WSL) involves
several steps, including installing WSL, installing necessary
dependencies, downloading the OpenCV source code, and compiling and
installing OpenCV. This blog post provides a step-by-step guide to help
you through the process.
Summary
The process of using OpenCV C++ on Windows Subsystem for Linux (WSL)
involves enabling WSL on your Windows system, installing a Linux
distribution (like Ubuntu), updating and installing required
dependencies, downloading the OpenCV and OpenCV Contrib source code,
configuring the build environment with CMake, compiling and installing
OpenCV, and finally verifying the installation by running a simple
OpenCV C++ program.
Step-by-Step Guide
Install WSL: Ensure that WSL is enabled on your
Windows 10 or higher system. You can run the following command in
PowerShell to enable WSL and install Ubuntu (or any other Linux
distribution of your choice):
| |
After restarting your computer, open the Microsoft Store, search for
Ubuntu, and install your preferred version.
Update and Install Dependencies: Launch your
Linux distribution (e.g., Ubuntu), and use the following commands to
update your package manager and install the required dependencies for
compiling OpenCV:
| |
Download OpenCV and OpenCV Contrib Source Code:
Download the OpenCV and OpenCV Contrib source code from the OpenCV
GitHub repository:
| |
Ensure both repositories are on the same version, e.g., OpenCV
4.x:
| |
Compile and Install OpenCV: Create a build
directory, configure the build environment using CMake, and then compile
and install OpenCV:
| |
Configure Environment Variables: To ensure the
compiler can find the OpenCV libraries, you need to update the
LD_LIBRARY_PATH environment variable. Add the following
line to your ~/.bashrc or ~/.profile file:
| |
Then, execute source ~/.bashrc or restart your terminal
application to apply the changes.
Verify Installation: Compile and run a simple
OpenCV program to verify the successful installation. You can create a
simple C++ program that uses OpenCV to read and display an
image.
By following these steps, you should be able to successfully set up
and use OpenCV C++ on the Windows Subsystem for Linux (WSL).
