How To Install OpenCV on Fedora 43

Computer vision has become an essential technology powering everything from smartphone cameras to autonomous vehicles. OpenCV (Open Source Computer Vision Library) stands as the most widely-used framework for computer vision applications, offering powerful tools for image processing, video analysis, and machine learning integration. For developers working on Fedora 43, installing OpenCV properly sets the foundation for building sophisticated computer vision projects. This comprehensive guide walks you through two proven installation methods, from the quick package manager approach to advanced source compilation, ensuring you can start developing computer vision applications immediately.
Understanding OpenCV and Its Capabilities
OpenCV is a cross-platform library containing over 2,500 optimized algorithms for real-time computer vision tasks. The library excels at image processing, facial recognition, object detection, motion tracking, and video analysis. Fedora 43 repositories currently provide OpenCV version 4.11.0, which includes extensive modules for both C++ and Python development. Linux systems like Fedora offer particular advantages for OpenCV development, including better performance optimization, easier integration with GPU acceleration, and seamless compatibility with other scientific computing libraries. Real-world applications span medical imaging analysis, robotics navigation, augmented reality, security surveillance systems, and autonomous vehicle perception.
Prerequisites and System Requirements
Before beginning the installation process, ensure your system meets the necessary requirements. You need a Fedora 43 installation with sudo or root privileges to install packages system-wide. The DNF installation method requires approximately 961 MB of disk space, while building from source may need additional space for source files and build artifacts. An active internet connection is essential for downloading packages and dependencies. Fedora 43 includes Python 3.9 or newer by default, which works perfectly with OpenCV’s Python bindings. Basic familiarity with terminal commands helps, though this guide provides detailed instructions for all experience levels.
Pre-Installation System Preparation
Preparing your Fedora system ensures a smooth installation process. Open your terminal and update all system packages first:
sudo dnf update
This command refreshes your package repositories and upgrades installed software to the latest versions. System updates prevent potential conflicts with outdated libraries and ensure compatibility with OpenCV dependencies. Check your Python version by running python3 --version to confirm you have Python 3.9 or later. Verify available disk space using df -h to ensure sufficient room for the installation.
Method 1: Installing OpenCV Using DNF Package Manager
The DNF package manager provides the fastest and simplest installation method for most users. This approach automatically handles dependency resolution, maintains consistent package versions, and simplifies future updates through Fedora’s standard package management system.
Installing Core OpenCV Packages
Execute the following command to install the primary OpenCV packages:
sudo dnf install opencv opencv-devel
The opencv package provides runtime libraries necessary for running OpenCV applications, while opencv-devel includes development headers and C/C++ library files required for compiling programs that use OpenCV. DNF will identify over 110 dependencies and display the total download and installation size. Type ‘y’ and press Enter to confirm the installation. The process typically completes within a few minutes, depending on your internet speed.
Adding Python Bindings and Extra Modules
For Python development and additional functionality, install supplementary packages:
sudo dnf install python3-opencv opencv-contrib opencv-doc
The python3-opencv package enables you to import and use OpenCV in Python scripts. The opencv-contrib package adds extra modules with advanced features like SIFT, SURF, and other experimental algorithms. The opencv-doc package provides local documentation for offline reference. Installing additional scientific computing libraries enhances OpenCV’s capabilities:
sudo dnf install python3-numpy python3-matplotlib
NumPy provides essential numerical computing functions, while Matplotlib enables visualization of processing results. These libraries integrate seamlessly with OpenCV for comprehensive computer vision workflows.
Method 2: Building OpenCV From Source
Compiling OpenCV from source offers maximum flexibility and access to the latest features. This advanced method suits developers who need custom configurations, specific optimizations, or OpenCV versions beyond what Fedora repositories provide.
Why Choose Source Compilation
Building from source grants several advantages. You gain access to cutting-edge OpenCV development versions with the newest algorithms and bug fixes. Custom compilation enables hardware-specific optimizations for your CPU or GPU, potentially improving performance significantly. You can selectively enable or disable modules based on project requirements, reducing the installation footprint. Camera support and video codec integration often work better with source-compiled installations, especially for specialized hardware. Contributors developing OpenCV features need source installations for testing and development workflows.
Installing Build Dependencies
Source compilation requires several development tools. Install the complete development toolchain:
sudo dnf install @development-tools
This command installs GCC compiler, Make utility, and essential build tools. Install CMake, which configures the OpenCV build system:
sudo dnf install cmake
CMake version 3.5.1 or higher is required for OpenCV 4.x compilation.
Installing Required Dependencies
Python development packages are mandatory for Python bindings:
sudo dnf install python3-devel python3-numpy
The python3-devel package provides Python header files necessary for compiling Python modules, while NumPy handles array operations fundamental to image processing.
Installing Optional Dependencies
Optional dependencies unlock additional OpenCV features. Install GUI support libraries for displaying images and videos:
sudo dnf install gtk3-devel
Add multimedia support for various video formats and codecs:
sudo dnf install ffmpeg-devel gstreamer1-plugins-base-devel
Enable camera support with Video4Linux:
sudo dnf install libv4l-devel libdc1394-devel
Install image format libraries for comprehensive file format support:
sudo dnf install libpng-devel libjpeg-turbo-devel libtiff-devel libwebp-devel jasper-devel OpenEXR-devel
Performance optimization libraries accelerate processing:
sudo dnf install tbb-devel eigen3-devel
These dependencies enhance OpenCV’s capabilities across different domains.
Downloading OpenCV Source Code
Install Git if not already present:
sudo dnf install git
Clone the official OpenCV repository:
git clone https://github.com/opencv/opencv.git
cd opencv
Optionally, clone opencv_contrib for extra modules:
git clone https://github.com/opencv/opencv_contrib.git
These commands download the complete OpenCV source code to your system.
Configuring the Build with CMake
Create a dedicated build directory inside the OpenCV source directory:
mkdir build
cd build
Run CMake with appropriate configuration flags:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
..
The CMAKE_BUILD_TYPE=RELEASE flag enables compiler optimizations for production use. The CMAKE_INSTALL_PREFIX specifies the installation location. If you cloned opencv_contrib, the OPENCV_EXTRA_MODULES_PATH parameter includes those additional modules. Carefully review CMake’s output, which displays detected dependencies, enabled features, and Python installation paths. Verify that Python 3 interpreter and NumPy are detected correctly.
Compiling OpenCV
Initiate the compilation process:
make -j$(nproc)
The -j$(nproc) flag utilizes all available CPU cores for parallel compilation, significantly reducing build time. Compilation duration varies based on system specifications, typically ranging from 15 minutes to over an hour. Monitor the terminal for any error messages. If compilation fails, review error outputs carefully and ensure all required dependencies are installed.
Installing Compiled OpenCV
After successful compilation, install OpenCV system-wide:
sudo make install
This command copies compiled libraries to /usr/local/lib, header files to /usr/local/include, and Python modules to the appropriate Python site-packages directory. Update the system’s shared library cache:
sudo ldconfig
This ensures the system recognizes newly installed OpenCV libraries.
Post-Installation Configuration
Proper configuration ensures OpenCV functions correctly across all applications. When building from source, verify Python can locate the cv2 module. Start a Python shell and try importing OpenCV. If imports fail, check your Python path:
import sys
print(sys.path)
Locate the cv2.so file in your OpenCV build directory and copy it to a directory in Python’s path if necessary. For C++ development, configure pkg-config by ensuring /usr/local/lib/pkgconfig is in your PKG_CONFIG_PATH environment variable. Fedora Silverblue and CoreOS users need special considerations, as these immutable variants require using rpm-ostree overlay for package installation.
Verifying OpenCV Installation
Thorough verification confirms successful installation and proper configuration.
Python Verification
Open a Python interactive session:
python3
Import OpenCV and check the version:
import cv2 as cv
print(cv.__version__)
The output should display the installed version, such as 4.11.0 for DNF installation or your compiled version number. No error messages indicate successful installation. Test basic functionality by creating a simple array:
import numpy as np
test_img = np.zeros((100, 100, 3), dtype=np.uint8)
print("OpenCV is working correctly!")
C/C++ Verification
Check OpenCV installation using pkg-config:
pkg-config --modversion opencv4
This command displays the installed OpenCV version. Verify compiler flags:
pkg-config --cflags opencv4
pkg-config --libs opencv4
These commands show include paths and linker flags needed for compiling C++ applications.
Testing Basic Functionality
Create a simple Python script to test image operations. Save this as test_opencv.py:
import cv2 as cv
import numpy as np
# Create a blank image
img = np.zeros((400, 400, 3), dtype=np.uint8)
# Draw a circle
cv.circle(img, (200, 200), 100, (0, 255, 0), -1)
# Save the image
cv.imwrite('test_output.png', img)
print("Test image created successfully!")
Run the script with python3 test_opencv.py. A green circle image confirms OpenCV is functioning properly.
Common Installation Issues and Troubleshooting
Even with careful preparation, installation challenges occasionally arise.
Missing Dependencies Error: DNF installations rarely encounter this issue, but source compilation may fail if dependencies are missing. Read error messages carefully, identify the missing package name, and install it using sudo dnf install package-name.
Python Import Errors: If Python cannot import cv2, the module may be installed in an unexpected location. Search for cv2.so file using find /usr -name "cv2*.so" and create a symbolic link to your Python site-packages directory.
CMake Configuration Failures: CMake may not detect certain libraries. Install development versions of packages (those ending with -devel) rather than runtime-only packages. Review CMake output carefully to identify which dependencies weren’t found.
Compilation Errors: Memory exhaustion during compilation is common on systems with limited RAM. Reduce parallel jobs by using make -j2 instead of make -j$(nproc). Alternatively, add swap space temporarily.
Version Conflicts: Multiple OpenCV installations can conflict. Uninstall previous versions before installing new ones. For DNF installations, use sudo dnf remove opencv*. For source installations, delete /usr/local/lib/libopencv* files.
Permission Denied Errors: Installation commands require administrative privileges. Always prefix installation commands with sudo. Regular compilation steps (cmake and make without install) should run without sudo.
Camera and Video Codec Issues: Limited codec support stems from missing FFmpeg or GStreamer libraries. Install multimedia dependencies mentioned earlier and recompile from source.
For persistent issues, consult the official OpenCV documentation, Fedora forums, or GitHub issue tracker. The OpenCV community actively helps troubleshoot installation problems.
Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing OpenCV on Fedora 43 Linux system. For additional help or useful information, we recommend you check the official OpenCV website.