This crates requires OpenCV system library to be present in your system. See below for some of the more common setups:
OpenCV package in Arch is suitable for this:
pacman -S clang qt6-base opencv
and additionally to support more OpenCV modules:
pacman -S vtk glew fmt openmpi
apt install libopencv-dev clang libclang-dev
zypper install opencv-devel clang-devel gcc-c++
You have several options of getting the OpenCV library:
-
install it from the repository, make sure to install
-dev
packages because they contain headers necessary for the crate build (also check that your package containspkg_config
orcmake
files). -
build OpenCV manually and set up the following environment variables prior to building the project with
opencv
crate:PKG_CONFIG_PATH
for the location of*.pc
files orOpenCV_DIR
for the location of*.cmake
filesLD_LIBRARY_PATH
for where to look for the installed*.so
files during runtime
Additionally, please make sure to install clang
package or its derivative that contains libclang.so
and
clang
binary.
- Gentoo, Fedora:
clang
- Debian, Ubuntu:
clang
andlibclang-dev
Installing OpenCV is easy through the following sources:
-
from chocolatey, also install
llvm
package, it's required for building:choco install llvm opencv
also set
OPENCV_LINK_LIBS
,OPENCV_LINK_PATHS
andOPENCV_INCLUDE_PATHS
environment variables (see below for details). -
from vcpkg, also install
llvm
package, necessary for building:vcpkg install llvm opencv4[contrib,nonfree]
You most probably want to set environment variable
VCPKGRS_DYNAMIC
to "1" unless you're specifically targeting a static build.
Get OpenCV from homebrew:
-
brew install opencv
You will also need a working C++ compiler and libclang, you can install Command Line Tools (
xcode-select --install
), XCode (from App Store) orllvm
(from Brew). You most probably need to also check the item 7 of the troubleshooting.If using system LLVM doesn't work for you, you can get it from homebrew:
brew install llvm
If you have already installed OpenCV via Homebrew, there is no need to configure any environment variables specifically for OpenCV on macOS. The OpenCV installation can be automatically detected if it was installed through Homebrew.
To take advantage of this automatic detection, refrain from setting the following environment variables:
OPENCV_LINK_LIBS
,OPENCV_LINK_PATHS
, andOPENCV_INCLUDE_PATHS
.However, make sure you have configured the following environment variables:
DYLD_FALLBACK_LIBRARY_PATH
,LDFLAGS
andLD_LIBRARY_PATH
.If you have not made any custom changes to your installation, the following settings should work for your setup:
export DYLD_FALLBACK_LIBRARY_PATH="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/lib/" export LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
You can of course always compile OpenCV of the version you prefer manually. This is also supported, but it requires some additional configuration.
You need to set up the following environment variables to point to the installed files of your OpenCV build:
OPENCV_LINK_LIBS
, OPENCV_LINK_PATHS
and OPENCV_INCLUDE_PATHS
(see below for details).
Static linking to OpenCV is supported and tested at least on Linux. For some hints on building OpenCV statically
please check this comment. Also,
you can get some information on how to perform the build in CI scripts:
install-ubuntu.sh and
script.sh, search for "static"
string.
Cross-compilation is supported to at least some extent. The ability to crosscompile projects using opencv
from x86-64
Linux host machine to Raspberry Pi is tested regularly. Cross-compilation is notoriously difficult to set up, so you can
use this example rpi-xcompile.Dockerfile.
docker build -t rpi-xcompile -f tools/docker/rpi-xcompile.Dockerfile tools
Building this image requries qemu-arm
to be present on the host system and the corresponding binfmt-misc
set up
- see e.g. https://wiki.debian.org/QemuUserEmulation, only
Installing packages
should be enough for debian-based distros, - for opensuse, install
qemu-linux-user
via zypper to set up the host correctly.
After the successful build you will have an image configured for cross-compilation to Raspberry Pi. It will contain the
sample build script /usr/local/bin/cargo-xbuild
that you can check for the correct environment setup and the specific
command line arguments to use when crosscompiling the project inside the container created from that image.