Git Product home page Git Product logo

ocv_demos's Introduction

OpenCV Rust Examples

A series of Rust examples on using OpenCV. These are almost all direct ports of other Python or C++ examples on the internet.

Prerequisits

sudo apt install libclang-dev
sudo apt install clang
sudo apt install libcanberra-gtk-module

Of course you will need to install OpenCV

git clone https://github.com/opencv/opencv.git
cd opencv/build
cmake ../ && make install

Along with the above prerequisits you will need to set the folling env vars in order to compile your rust project

# location of your opencv cmake file ( e.g. find /usr -name "OpenCV*cmake")
PKG_CONFIG_PATH=/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake

# location of opencv *.so files
LD_LIBRARY_PATH=/usr/local/lib/

Build project

cargo build 

Examples

Image Filtering Example

This is more an example of Rusts powerful lambda capabilites used to select pixels above a given threshold in an image.

cargo run -- filter -f <image_file> -t <threshold_u8>

Finding Centroid / Blobs Example

This example is a Rust port of the following example on learnopencv.com

cargo run -- centroid -f <image_file>

Notes on Cross Compiling

e.g. aarch64-unknown-linux-gnu

prerequisits

sudo apt-get install g++-aarch64-linux-gnu

Cross-Compile / Build (for aarch64)

To cross-compile for aarch64 you will need to edit the following: ~/.cargo/config

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
rustup target list
rustup target add aarch64-unknown-linux-gnu 
cargo build --target aarch64-unknown-linux-gnu

Cross-Compile / OpenCV (for aarch64)

To cross-compile OpenCV for aarch64 you can do the following from the OpenCV source folder:

cmake -B build -S. \ 
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DCMAKE_INSTALL_PREFIX=/usr/local \ -DOPENCV_GENERATE_PKGCONFIG=ON  \
    -DWITH_QT=OFF \
    -DWITH_QT=ON \
    -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake .. \
    && cd build \
    && make -j16 

Armv7 / armhf

sudo dpkg --add-architecture armhf

~.cargo/config

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
rustup target add armv7-unknown-linux-gnueabihf
cargo build --target armv7-unknown-linux-gnueabihf

https://docs.opencv.org/4.x/d0/d76/tutorial_arm_crosscompile_with_cmake.html

https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.