OpenCV (Open Source Computer Vision Library) is widely used for computer vision applications. This guide provides step-by-step instructions to install OpenCV on a Windows system.
Ensure your system meets the following prerequisites:
- A Windows operating system
- Microsoft Visual Studio (2015, 2017, 2019)
- Python (optional, for Python bindings)
- Basic knowledge of the command line
Before installing OpenCV, ensure you have Microsoft Visual Studio installed. You can download it from Visual Studio.
Downloading OpenCV
Download the latest OpenCV release from the OpenCV official site. Extract the downloaded file to a directory (e.g., C:\opencv
).
Setting Up Environment Variables
Set up the environment variables to make OpenCV accessible system-wide:
- Right-click on ‘This PC’ and select ‘Properties.’
- Click on ‘Advanced system settings.’
- Click on ‘Environment Variables.’
- In the ‘System variables’ section, find the ‘Path’ variable and click ‘Edit.’
- Add the path to the OpenCV bin directory (e.g.,
C:\opencv\build\x64\vc15\bin
).
Building OpenCV from Source
- Open CMake (download from cmake.org).
- Specify the source folder (
C:\opencv\opencv
) and the build folder (e.g.,C:\opencv\build
). - Click ‘Configure’ and select your version of Visual Studio.
- After configuration, click ‘Generate.’
- Open the generated solution file (
OpenCV.sln
) with Visual Studio. - Build the solution in Release mode.
Verifying Installation
To verify the installation, open the Python interpreter and import OpenCV (if Python bindings were included):
import cv2
print(cv2.__version__)
If installed correctly, the version number will be displayed.
Following this guide, you should have OpenCV installed on your Windows system, ready for developing computer vision applications. OpenCV provides a robust platform for various image and video processing tasks. For more detailed information and troubleshooting, refer to the OpenCV installation guide for Windows.