openSUSE

How To Install OpenCV on openSUSE

Install OpenCV on openSUSE

OpenCV, or Open Source Computer Vision Library, is a powerful tool for image processing and computer vision projects. It provides a comprehensive set of functionalities that enable developers to work with images and videos effectively. This guide will walk you through the step-by-step process of installing OpenCV on openSUSE, ensuring that you have all the necessary tools and libraries to get started with your computer vision projects.

Prerequisites

System Requirements

Before diving into the installation process, ensure that your system meets the following minimum hardware specifications:

  • Processor: Dual-core CPU or higher.
  • RAM: At least 4 GB (8 GB recommended).
  • Disk Space: Minimum of 2 GB free space for installation.

Software Dependencies

OpenCV requires several software packages to function correctly. Below is a list of essential dependencies:

  • CMake: A tool for managing the build process.
  • GCC/G++: The GNU Compiler Collection for compiling C and C++ code.
  • Git: A version control system to clone the OpenCV repository.

You can check if these packages are installed by running the following command in your terminal:

zypper se cmake gcc gcc-c++ git

Setting Up the Environment

Updating openSUSE

The first step in setting up your environment is to ensure that your openSUSE installation is up-to-date. Open a terminal and execute the following command:

sudo zypper refresh && sudo zypper update

Installing Required Packages

Once your system is updated, install the required packages using the command below:

sudo zypper install gcc gcc-c++ cmake git

Adding Repositories

OpenCV may require additional libraries that are not included in the default repositories. To add the multimedia and development libraries repositories, use the following commands:

sudo zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/Multimedia/ packman-multimedia
sudo zypper refresh

Downloading OpenCV

Choosing the Version

You can choose to install either the latest stable version or a specific version of OpenCV. For most users, it is advisable to use the latest stable release. You can check the available versions on the official OpenCV GitHub page.

Downloading from GitHub

The next step is to clone the OpenCV repositories from GitHub. Use the following commands in your terminal:

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

Building OpenCV from Source

Creating a Build Directory

A clean build directory helps keep your source files organized. Navigate to the OpenCV directory and create a build folder:

cd opencv
mkdir build
cd build

Configuring the Build with CMake

CMake allows you to configure OpenCV’s build options. Run the following command to configure your build settings, specifying any additional modules you want to include from opencv_contrib:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..

Compiling OpenCV

The compilation process can take some time depending on your system’s performance. Start compiling by executing:

make -j$(nproc)

The `-j$(nproc)` flag allows make to utilize multiple cores, speeding up the compilation process significantly.

Installing OpenCV

After successful compilation, install OpenCV using the following command:

sudo make install
sudo ldconfig

Verifying the Installation

Checking Installed Files

You can verify that OpenCV has been installed correctly by checking for its binaries and libraries in `/usr/local/lib` and `/usr/local/bin` directories.

Running a Sample Program

Create a simple C++ program to test if OpenCV is functioning correctly. Create a file named `test_opencv.cpp` and add the following code snippet:

#include <opencv2/opencv.hpp>

int main() {
    cv::Mat image = cv::imread("test.jpg");
    if (image.empty()) {
        std::cerr << "Could not open or find the image!" << std::endl;
        return -1;
    }
    cv::imshow("Test Image", image);
    cv::waitKey(0);
    return 0;
}

This code reads an image named `test.jpg` and displays it in a window. Compile this program with:

g++ test_opencv.cpp -o test_opencv `pkg-config --cflags --libs opencv4`

Troubleshooting Common Issues

Installation Errors

If you encounter errors during installation, check for missing dependencies or incorrect paths in your CMake configuration. Ensure that all required packages are installed and that you have specified correct paths for any additional modules.

Dependency Issues

If certain libraries are missing after installation, you may need to install them manually using zypper. For example, if you encounter issues with image formats, consider installing additional libraries like `libjpeg`, `libpng`, or `libtiff`:

sudo zypper install libjpeg-devel libpng-devel libtiff-devel

Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing the OpenCV (Open Source Computer Vision Library) on openSUSE. For additional help or useful information, we recommend you check the official OpenCV website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a dedicated and highly skilled Linux Systems Administrator with over a decade of progressive experience in designing, deploying, and maintaining enterprise-grade Linux infrastructure. His professional journey began in the telecommunications industry, where early exposure to Unix-based operating systems ignited a deep and enduring passion for open-source technologies and server administration.​ Throughout his career, r00t has demonstrated exceptional proficiency in managing large-scale Linux environments, overseeing more than 300 servers across development, staging, and production platforms while consistently achieving 99.9% system uptime. He holds advanced competencies in Red Hat Enterprise Linux (RHEL), Debian, and Ubuntu distributions, complemented by hands-on expertise in automation tools such as Ansible, Terraform, Bash scripting, and Python.
Back to top button