Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Hello World with opencv-rust

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use opencv-rust to achieve Hello World", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use opencv-rust to achieve Hello World.

Opencv-rust install $sudo apt install clang- y $sudo apt install libclang-dev-y opencv$ opencv_version4.5.1 / first install opencv$ opencv_version4.5.1 write an example

Cargo.toml

Opencv = {version = "0.52", default-features = false, features = ["opencv-34", "buildtime-bindgen"]}

Main.rs

If the operation fails, you need to install a Microsoft tool-- vcpkg

$git clone https://github.com/microsoft/vcpkg$. / vcpkg/bootstrap-vcpkg.sh$ sudo cp vcpkg/ usr/bin$ vcpkg install boost:x64-linux$ export VCPKG_ROOT=/usr/local/vcpkg$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDAROOT/lib64:/usr/lib/x86_64-linux-gnu:/usr/local/lib$ export export PKG_CONFIG_PATH=/usr/local/vcpkg/installed/x64-linux/lib/pkgconfig/:/usr/share/pkgconfig/:/usr/local/lib/pkgconfig/

Encountered a strange problem.

Error: "Failed to find OpenCV package using probes: environment, pkg_config, vcpkg_cmake, vcpkg, cmake"

After searching all over google, baidu and bing, I couldn't find the reason, and then it came true, as I often say, "when you can't find any records about this problem, it's your own problem."

I tried to execute the following statement

$pkg-config-modversion opencv3.2.0

Do you remember how I defined it in Cargo.toml?

Opencv = {version = "0.52", default-features = false, features = ["opencv-34", "buildtime-bindgen"]}

I changed it to

Opencv = {version = "0.52", default-features = false, features = ["opencv-32", "buildtime-bindgen"]}

This problem is solved, but it is still compiled, but there are all kinds of syntax errors at this time. It seems that I have to upgrade the version to 3.4.0.

Later found that it is Oolong, there is no problem with using opencv-32, because the original program needs a picture, I did not put it under the current path.

The final compilation process:

$RUST_BACKTRACE=full cargo build-vv

But video still doesn't work. I have to work hard to upgrade opencv. It has to be 3.4.

$sudo apt-get purge libopencv* python-opencv$ sudo apt-get install libopencv* python-opencv$ pip3 uninstall opencv-python-headless

Install opencv_3.4.14

$sudo apt-get install build-essential$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22 Murdo $git clone https://github.com/opencv/opencv.git$ cd opencv$ mkdir build$ cd build$ sudo cmake-D WITH_TBB=ON-D BUILD_NEW_PYTHON_SUPPORT=ON-D WITH_V4L=ON-D INSTALL_C_EXAMPLES=ON-D INSTALL_PYTHON_ EXAMPLES=ON-D BUILD_EXAMPLES=ON-D WITH_QT=ON-D WITH_OPENGL=ON-D CMAKE_LIBRARY_PATH=/usr/local/cuda-11.0/lib64/stubs-D CUDA_CUDA_LIBRARY=/usr/local/cuda-11.0/lib64/stubs/libcuda.so.. $sudo make-J8 $sudo make install https://github.com/opencv/opencv/tree/3.4.14 download a zip package here and the installation method is the same as the last one above

: tada:tada:tada:tada:tada:tada:tada:tada:tada:tada:tada:

Here is a simple example

Cargo.toml

Opencv = {version = "0.52", default-features = false, features = ["opencv-34", "buildtime-bindgen"]} use opencv:: {highgui, imgcodecs, Result,}; fn main ()-> Result {let image = imgcodecs::imread ("lena.jpg", imgcodecs::IMREAD_ANYCOLOR)?; highgui::named_window ("hello opencv!", 0)? Highgui::imshow ("hello opencv!", & image); highgui::wait_key (10000)?; Ok (())} $RUST_BACKTRACE=full cargo build-vv

It was a great success.

At this point, I believe you have a deeper understanding of "how to use opencv-rust to achieve Hello World". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report