A primer on using OpenCV with Rust.
- Rust bindings for OpenCV - repository and examples
- Rust bindings for OpenCV - documentation
- OpenCV C++ documentation
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
Get the latest version:
wget https://github.com/opencv/opencv/archive/4.2.0.zip ~/Downloads
Create a directory and unzip it:
sudo mkdir /opt/opencv
sudo unzip ~/Downloads/opencv-4.2.0.zip -d /opt/opencv
Create symlink latest
pointing to the current version of OpenCV:
cd /opt/opencv
sudo ln -s opencv-4.2.0 latest
In the future you can unlink it and create new symlink with:
sudo unlink /opt/opencv/latest
sudo ln -s opencv-X.X.X latest
Create a temporary build directory:
cd /opt/opencv/latest
sudo mkdir release
Generate build files:
cd /opt/opencv/latest/release
sudo cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=YES -DCMAKE_INSTALL_PREFIX=/opt/opencv/opencv-4.2.0 /opt/opencv/opencv-4.2.0
Build and install:
cd /opt/opencv/latest/release
sudo make -j4
sudo make install
Update links/cache used by the dynamic loader:
sudo ldconfig
Add to .bashrc:
export PATH=/opt/opencv/latest/bin:/opt/opencv/latest/release/bin:${PATH}
export LD_LIBRARY_PATH=/opt/opencv/latest/release/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/opt/opencv/latest/lib/pkgconfig
export OPENCV_TEST_DATA_PATH=/opt/opencv/latest/opencv_extra-master/testdata
Or if your're using fish:
# OpenCV paths
set -gx PATH /opt/opencv/latest/bin $PATH
set -gx PATH /opt/opencv/latest/release/bin $PATH
set -gx LD_LIBRARY_PATH /opt/opencv/latest/release/lib $LD_LIBRARY_PATH
set --export PKG_CONFIG_PATH /opt/opencv/latest/lib/pkgconfig
set --export OPENCV_TEST_DATA_PATH /opt/opencv/latest/opencv_extra-master/testdata
You need to export the OPENCV_TEST_DATA_PATH
env variable and copy two files named lena.jpg
and lena.png
to the release directory
export OPENCV_TEST_DATA_PATH=/opt/opencv/latest/opencv_extra-master/testdata
sudo cp ~/Dropbox/Rust/opencv/lena.png /opt/opencv/latest/release/bin/lena.png
sudo cp ~/Dropbox/Rust/opencv/lena.jpg /opt/opencv/latest/release/bin/lena.jpg
cd /opt/opencv/latest/release
sudo ./bin/opencv_test_core