Skip to main content

Installation

Prerequisites

System Dependencies Ubuntu/Debian:

bash
sudo apt update
sudo apt install -y cmake pkg-config libssl-dev
sudo apt install -y libopencv-dev clang libclang-dev
CentOS/RHEL:
bash
sudo yum install -y cmake pkg-config openssl-devel
sudo yum install -y opencv-devel clang clang-devel

macOS:

bash
brew install cmake pkg-config openssl
brew install opencv

Windows:

  • Install Visual Studio Build Tools

  • Install vcpkg: vcpkg install opencv4:x64-windows

  • Set environment variables

Cargo Configuration

Basic Installation

Add to Cargo.toml:

toml
[dependencies]
opencv = "0.88"

Feature Selection

toml
[dependencies]
opencv = { version = "0.88", features = ["opencv-4"] }

Development Dependencies

toml
[dev-dependencies]
opencv = { version = "0.88", features = ["opencv-4", "buildtime-bindgen"] }

Build Configuration

Environment Variables

bash
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
export OPENCV_LINK_LIBS=opencv_core,opencv_imgproc,opencv_imgcodecs
export OPENCV_LINK_PATHS=/usr/lib/x86_64-linux-gnu

Cross-compilation Setup

toml
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[env]
OPENCV_HEADER_DIR = "/usr/include/opencv4"
OPENCV_PACKAGE_NAME = "opencv4"

Docker Installation

dockerfile
FROM rust:1.70
RUN apt-get update && apt-get install -y \
cmake pkg-config libssl-dev \
libopencv-dev clang libclang-dev
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
RUN cargo build --release
COPY . .
RUN cargo build --release