Library / SDK
twistedfall/opencv-rust avatar
twistedfall/opencv-rust

opencv-rust generates its bindings with Clang at build time, so the build needs OpenCV, Clang and the right environment variables

OpenCV API bindings for Rust

2,503 stars185 forksRustMIT

At a glance

What is it?
twistedfall/opencv-rust wraps OpenCV 4.x and 5.x for Rust. Crate version 0.101.1 generates the bindings during the build, which makes discovery of the OpenCV install the part that fails most often.
Who is it for?
Use opencv-rust if you want OpenCV from Rust and can install OpenCV and Clang on every machine that builds the crate, including CI. Do not use it if you need a stable API or a build with no system dependencies, since the README calls the API usable but unstable and not very battle-tested.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 16 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • twistedfall/opencv-rust2,503 ★ · +8
Star history
Repository2026-10-082026-11-25
twistedfall/opencv-rust2.5k2.5k

8 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The README calls the API usable, unstable and not very battle-tested

The project states its maturity in one line: the API is usable, but unstable and not very battle-tested, so use at your own risk. The version number agrees. The crate is at 0.101.1, in the 0.x range where breaking changes are expected between releases.

The repository links a CHANGES.md changelog, a TROUBLESHOOTING.md and a sponsorship page. When a minor version moves, the changelog is where you find what changed in the Rust-facing API. The binding-generator workspace member has its own version, 0.107.0, so the two numbers do not move together.

The crate requires rust-version 1.88.0 and uses edition 2024. A project on an older compiler has to upgrade the toolchain before it can compile the dependency. The package metadata files the crate under the categories api-bindings, computer-vision, external-ffi-bindings and multimedia, with the keywords opencv, vision and cv. Doctests are switched off for the library, so the documentation examples on docs.rs are not compiled as tests in this repository.

Quickstart is a Cargo line and one prelude import, after OpenCV and Clang are installed

The setup the README lists comes first: a supported OpenCV version, 4.x or 5.x, and Clang, which is part of LLVM and is needed for automatic binding generation. OpenCV 3.4 is still supported but deprecated and will be removed in a future release.

Then the Cargo.toml line:

toml
opencv = "0.101.1"

And the import:

rust
use opencv::prelude::*;

That is the whole quickstart. The bindings are not checked into the crate as static code. They are generated from the headers of the OpenCV you installed, which is why Clang is a hard requirement and why the same crate version can expose different APIs depending on the OpenCV version on the build machine.

For installing OpenCV, the README refers to INSTALL.md rather than repeating steps.

Finding OpenCV: pkg_config, cmake, vcpkg, or three environment variables

The build probes for OpenCV through several systems, and the README names pkg_config, cmake and vcpkg. When none of them works, you set variables by hand.

OPENCV_LINK_LIBS is a comma-separated list of libraries to link, with optional dylib=, static= or framework= prefixes. The README's examples are opencv_world411 and framework=OpenCL. OPENCV_LINK_PATHS lists the directories to search for libraries, and OPENCV_INCLUDE_PATHS lists the directories for headers. One include directory must contain opencv2/core/version.hpp or core/version.hpp, because that file is used to detect the version of the headers.

The README says these three must be set when building without pkg_config, cmake or vcpkg, and that when set on any platform they override whatever was discovered automatically.

A leading plus sign appends to the probe result instead of replacing it

All three variables accept a leading + character. A value of +dc1394 for OPENCV_LINK_LIBS first does a system discovery of OpenCV and its linked libraries, then links dc1394 at the end. The README gives the use case: the system probe produces a mostly working setup but has an incomplete link list, or the order is wrong, which matters especially during static linking.

For paths the same form applies, as in +/usr/local/lib for OPENCV_LINK_PATHS and +/opt/cuda/targets/x86_64-linux/include/ for OPENCV_INCLUDE_PATHS.

Without the plus sign, your list replaces the probe's, so a partial list can leave out libraries the probe found. If the build links most of OpenCV and then fails on one missing symbol, the plus form is the targeted fix.

Less common knobs: package names, cmake, probes and the MSVC runtime

OPENCV_PACKAGE_NAME overrides the pkg-config, cmake or vcpkg package name. pkg-config then expects a file with that name and a .pc extension, cmake looks for a .cmake file, and vcpkg tries that name under the packages directory of VCPKG_ROOT. Separate variables exist per system: OPENCV_PKGCONFIG_NAME, OPENCV_CMAKE_NAME and OPENCV_VCPKG_NAME.

OPENCV_CMAKE_BIN points at a cmake binary, and otherwise plain cmake is used. OPENCV_CMAKE_TOOLCHAIN_FILE passes -DCMAKE_TOOLCHAIN_FILE=<value> to cmake, which the README suggests for cross-compiling, and OPENCV_CMAKE_ARGS passes extra arguments parsed under POSIX command line rules.

OPENCV_DISABLE_PROBES takes a comma-separated list of discovery systems to skip: environment, pkg_config, cmake, vcpkg_cmake and vcpkg. It helps when a higher priority system gives wrong results. OPENCV_MSVC_CRT picks the CRT on Windows, with the values static for /MT and dynamic for /MD.

Runtime library paths differ by platform, and Windows wants UNIX-style PATH entries

Building is one problem and running is another. On Linux, LD_LIBRARY_PATH must contain the libopencv_*.so files. On macOS, DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH play the same role for *.dylib files. PKG_CONFIG_PATH must contain opencv.pc for versions before OpenCV 4 or opencv4.pc for OpenCV 4 and later. OpenCV_DIR points to the directory with OpenCVConfig.cmake, OpenCVConfig-version.cmake and OpenCVModules.cmake.

On Windows, DLLs are searched for in PATH among other places. You either set PATH or copy the OpenCV DLLs next to your binary. The README adds a detail that is easy to get wrong: specify paths in UNIX style, such as /C/Program Files/Dir, because a colon in PATH might be read as an entry separator.

OPENCV_CLANG_ARGS passes custom arguments to Clang for generating and parsing code, and the README's text on it is cut off.

Examples cover cameras, DNN face detection, CUDA, OpenCL and G-API

The examples directory shows what the bindings reach. There are camera_calibration.rs, create_mask.rs, discrete_fourier_transform.rs, hough_circle.rs, hough_lines.rs, warp_perspective_demo.rs and window.rs. Video examples include video_capture.rs, video_capture_http_stream.rs, video_facedetect.rs, video_features.rs and video_to_gray.rs. Others are dnn_face_detect.rs, text_detection.rs, cuda.rs, opencl.rs and gapi_api_example.rs.

Cargo.toml shows the dependencies: libc, num-traits, and optional half and rgb crates. On Windows the windows crate with Direct3D 9, 10 and 11 features is added. Build dependencies include cc, pkg-config, vcpkg and the workspace member opencv-binding-generator.

The repository is not archived, its license is MIT and its last push was on 2026-10-09. There are no GitHub releases, so published versions are found on crates.io, with CHANGES.md describing each one.

Top-level directories give a sense of the build: binding-generator holds the generator crate, src_cpp holds C++ glue, and cmake, build, ci, docs, tests and tools sit beside them. An AGENTS.md file is also present for AI coding assistants. If a build fails, TROUBLESHOOTING.md lists common issues and their solutions, and it is the first file to open before filing a report.

Editorial conclusion

Use opencv-rust if you want OpenCV from Rust and can install OpenCV and Clang on every machine that builds the crate, including CI. Do not use it if you need a stable API or a build with no system dependencies, since the README calls the API usable but unstable and not very battle-tested. Before adopting it, build the dnn_face_detect or video_capture example on your target platform, and read INSTALL.md and TROUBLESHOOTING.md first. The repository has no GitHub releases and its last push was on 2026-10-09.

Frequently asked questions

What is opencv-rust?

opencv-rust provides Rust bindings for OpenCV. The crate is called opencv, and it generates the bindings with Clang during the build.

Which OpenCV versions does opencv-rust support?

OpenCV 4.x and 5.x are supported. OpenCV 3.4 is still supported but deprecated and will be removed in a future release.

How do I add opencv-rust to a Rust project?

Install OpenCV and Clang, add opencv = "0.101.1" to Cargo.toml, and import use opencv::prelude::*;. INSTALL.md covers the system dependencies.

Official sources

  1. Issues
  2. License: MIT
  3. README
  4. twistedfall/opencv-rust on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/twistedfall-opencv-rust.svg)](https://hysenlabs.com/projects/twistedfall-opencv-rust)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/twistedfall-opencv-rust.svg)](https://hysenlabs.com/projects/twistedfall-opencv-rust)

Was this useful?