How To Install OpenCV on Fedora 39
In this tutorial, we will show you how to install OpenCV on Fedora 39. OpenCV, an open-source computer vision and machine learning software library, is widely recognized for its extensive range of image processing and computer vision capabilities. From facial recognition to object tracking, OpenCV provides a solid foundation for developing cutting-edge applications. However, to fully utilize OpenCV’s features, you need to install it correctly on your Fedora 39 system. In this guide, we will take you through the process, ensuring that you can seamlessly integrate OpenCV into your Linux environment.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the OpenCV on a Fedora 39.
Prerequisites
Before diving into the installation process, let’s ensure that you have everything you need:
- A server running one of the following operating systems: Fedora 39.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- You’ll need an active internet connection to download OpenCV and its dependencies.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install OpenCV on Fedora 39
Step 1. First, update your system’s package repositories and upgrade existing packages. This ensures that you have the latest software packages and dependencies.
sudo dnf clean all sudo dnf update
Step 2. Installing Essential Packages and Development Tools.
You’ll need a set of packages and development tools to compile and build OpenCV successfully. Use the following command to install them:
sudo dnf install cmake gcc-c++ python3 python3-pip numpy gtk2-devel libdc1394-devel libv4l-devel gstreamer-plugins-base-devel libxine2-devel libvpx-devel libavcodec-devel libavformat-devel libswscale-devel libv4l-devel libxvidcore-devel libx264-devel tbb-devel eigen3-devel openexr-devel boost-python3-devel
These packages provide the necessary tools and libraries to support OpenCV’s features and functions.
Step 3. Setting Up Python Virtual Environment.
Creating a Python virtual environment is a best practice as it isolates your OpenCV installation from the system’s default Python setup. This helps prevent conflicts and ensures a clean installation.
Create a directory for your project, and within that directory, create a virtual environment. Replace ‘my_opencv_env
‘ with your preferred environment name:
mkdir my_opencv_project cd my_opencv_project python3 -m venv my_opencv_env
To activate your virtual environment, use the following command:
source my_opencv_env/bin/activate
You should see the environment name in your terminal prompt, indicating that you are working within the virtual environment.
Step 4. Installing OpenCV on Fedora 39.
Now that your system is prepared, it’s time to download the OpenCV source code, configure the build using CMake, and compile the OpenCV libraries. Go to the directory where you want to store the OpenCV source code and use Git to clone the repository:
git clone https://github.com/opencv/opencv.git
Next, clone the extra modules repository:
git clone https://github.com/opencv/opencv_contrib.git
These repositories contain the core OpenCV code and additional modules that extend its capabilities.
Create a ‘build’ directory inside your OpenCV source code directory:
mkdir -p ~/my_opencv_project/opencv/build cd ~/my_opencv_project/opencv/build
Now, use CMake to configure the build. This command may vary based on your specific requirements, so make sure to adjust it accordingly.
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/my_opencv_project/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON ..
These settings ensure that OpenCV is built with examples and Python support. The OPENCV_EXTRA_MODULES_PATH
should point to the ‘modules’ directory inside your opencv_contrib repository.
Once the configuration is complete, compile and install OpenCV:
make -j4 sudo make install
Step 5. Verifying the Installation.
Now that OpenCV is installed, it’s crucial to verify the installation to ensure everything is functioning correctly.
Let’s test your OpenCV installation by running a simple Python script. Create a Python script, e.g., ‘opencv_test.py
,’ with the following content:
import cv2 print(cv2.__version__)
Save the script and run it:
python opencv_test.py
This should print the OpenCV version you installed. If the script runs without errors, your installation is successful.
To check the installed OpenCV version and available functionalities, you can use the following Python code:
import cv2 print("OpenCV Version:", cv2.__version__) print("Available OpenCV functionalities:") print(cv2.getBuildInformation())
Running this script will provide detailed information about your OpenCV installation.
Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing the OpenCV on your Fedora 39 system. For additional Apache or useful information, we recommend you check the official OpenCV website.