Closed hyousefGopher closed 4 years ago
Please also set OPENCV_LINK_LIBS
to "opencv_world412" (adjust for your opencv version), without all three (OPENCV_LINK_LIBS, OPENCV_LINK_PATHS, OPENCV_INCLUDE_PATHS) the crate doesn't have enough info to find opencv and tries to rely on external tools.
I've this setup already, even once I changed it to "opencv_world412" still getting the same msg:
Well, the build log says:
OPENCV_LINK_LIBS = None
so something is not right. Here another Windows user is mentioning the need to restart so you can maybe try that.
Did you have any luck?
Just rebooted by device, and got the below:
I suggest you check the whole thread in #113, that error was also mentioned there (and solved).
I copied all the .dll
files and got below error, actually I could not find anywhere n my PC a file named opencv_world
:
I just downloaded it from here but not sure where shall I put it
I believe that when you install OpenCV from vcpkg you get different modules in separate files, so you should have opencv_core, opencv_imgproc and do on. But generally can you please post the full output of the following command:
cargo clean
cargo build -vv
mm, before the full log, actuall I installed opencv in multiple way, from python, from GoCV 'faileda from chocolaty and vcpkg, trying to do cleaning to avoid conflicting issues, anyhow, here is the full log as it is very long:
https://gist.github.com/hyousef-rusty/7e41a48c35754b70696081f62887250a
As far as I can see there is a version mismatch between what you have in headers and library file name:
[opencv 0.34.0] version: "4.1.2",
...
[opencv 0.34.0] "cargo:rustc-link-lib=opencv_world420",
So I believe you installed version 4.1.2 so you'd need to link to opencv_world412
(the value of OPENCV_LINK_LIBS env var). You should have this file (both lib and dll) in your C:\\tools\\opencv\\build\\x64\\vc14\\lib
directory, do not download it from anywhere.
Oooof, finally got it, I removed everything I've though I'm not sure if really required, but wanted to do as fresh install.
Install Chocolatey
Installed OpenCV and LLVM as choco install llvm opencv
Add the below Environmental variables:
Restarted the PC for Env changes to take place
Built the Cargo.toml
as"
[dependencies]
opencv = {version = "0.34", features = ["buildtime-bindgen"]}
Built the src/main.rs
as:
use opencv::{
core,
highgui,
prelude::*,
videoio,
};
fn run() -> opencv::Result<()> { let window = "video capture"; highgui::named_window(window, 1)?;
let mut cam = videoio::VideoCapture::new_default(0)?; // 0 is the default camera
#[cfg(not(feature = "opencv-32"))]
let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY)?; // 0 is the default camera
let opened = videoio::VideoCapture::is_opened(&cam)?;
if !opened {
panic!("Unable to open default camera!");
}
loop {
let mut frame = core::Mat::default()?;
cam.read(&mut frame)?;
if frame.size()?.width > 0 {
highgui::imshow(window, &mut frame)?;
}
let key = highgui::wait_key(10)?;
if key > 0 && key != 255 {
break;
}
}
Ok(())
}
fn main() { run().unwrap() }
7. Build executable as: `cargo build`
8. Add the `opencv_worldxxx.dll` to the same location of the `.exe` file
![image](https://user-images.githubusercontent.com/60115476/80317125-90496100-880a-11ea-95fa-44a51a6b1308.png)
9. Run the executable as `cargo run`:
![image](https://user-images.githubusercontent.com/60115476/80317174-d999b080-880a-11ea-8f95-dad0b47930ac.png)
I’m glad it worked!
For opencv = "0.53"
let mut frame = core::Mat::default();
Only this line should not have ? operator (Rust documentation). Others return std::result
.
Hi, I also cannot use opencv on windows https://github.com/twistedfall/opencv-rust/issues/326. Could anyone give some hints? Thanks!
let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY).expect("Problems in taking pictures");
let opened = videoio::VideoCapture::is_opened(&cam)?;
if !opened {
panic!("No camera on");
}
let mut v = VectorOfu8::new();
cam.read(&mut v).expect("Error reading");
Why does this code cause an error in reading?
let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY).expect("Problems in taking pictures"); let opened = videoio::VideoCapture::is_opened(&cam)?; if !opened { panic!("No camera on"); } let mut v = VectorOfu8::new(); cam.read(&mut v).expect("Error reading");
Why does this code cause an error in reading?
I use version 0.70
Can you please open a new issue and post the full output you're getting in console?
let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY).expect("Problems in taking pictures"); let opened = videoio::VideoCapture::is_opened(&cam)?; if !opened { panic!("No camera on"); } let mut v = VectorOfu8::new(); cam.read(&mut v).expect("Error reading");
Why does this code cause an error in reading?
I use version 0.70
The following is all the information related to this problem that I got on the console
thread 'main' panicked at 'Error reading: Error { code: -215, message: "OpenCV(4.6.0) c:\\build\\master_winpack-build-win64-vc15\\opencv\\modules\\core\\src\\matrix_wrap.cpp:1373: error: (-215:Assertion failed) d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) in function 'cv::_OutputArray::create'\n" }', src\test.rs:16:22
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\std\src\panicking.rs:584
1: core::panicking::panic_fmt
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\core\src\panicking.rs:142
2: core::result::unwrap_failed
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\core\src\result.rs:1814
3: enum$<core::result::Result<bool,opencv::error::Error> >::expect<bool,opencv::error::Error>
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52\library\core\src\result.rs:1064
Try using Mat::default()
instead of VectorOfu8::new()
, the image you're reading is multichannel it looks like so one pixel doesn't fit into u8
. You should also check this example: https://github.com/twistedfall/opencv-rust/blob/master/examples/video_capture.rs
@twistedfall So what should I do if I want to get a picture file through the camera? What is the format of the picture?
Oooof, finally got it, I removed everything I've though I'm not sure if really required, but wanted to do as fresh install.
- Install Chocolatey
- Installed OpenCV and LLVM as
choco install llvm opencv
- Add the below Environmental variables:
- Restarted the PC for Env changes to take place
- Built the
Cargo.toml
as"[dependencies] opencv = {version = "0.34", features = ["buildtime-bindgen"]}
- Built the
src/main.rs
as:use opencv::{ core, highgui, prelude::*, videoio, }; fn run() -> opencv::Result<()> { let window = "video capture"; highgui::named_window(window, 1)?; #[cfg(feature = "opencv-32")] let mut cam = videoio::VideoCapture::new_default(0)?; // 0 is the default camera #[cfg(not(feature = "opencv-32"))] let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY)?; // 0 is the default camera let opened = videoio::VideoCapture::is_opened(&cam)?; if !opened { panic!("Unable to open default camera!"); } loop { let mut frame = core::Mat::default()?; cam.read(&mut frame)?; if frame.size()?.width > 0 { highgui::imshow(window, &mut frame)?; } let key = highgui::wait_key(10)?; if key > 0 && key != 255 { break; } } Ok(()) } fn main() { run().unwrap() }
- Build executable as:
cargo build
- Add the
opencv_worldxxx.dll
to the same location of the.exe
file
- Run the executable as
cargo run
:
I followed the exact steps and im getting these errors [note that i didnt do anything related to vcpkg manager and used only choco but its asking to use vcpkg configs something.. ] later on i installed pkg_config and am still trying but that step was never mentioned anywhere thats why asking rn @twistedfall
Compiling opencv v0.74.2
error: failed to run custom build command for `opencv v0.74.2`
Caused by:
process didn't exit successfully: `F:\LANGS\RUST\lvp-2\target\debug\build\opencv-f4bc7b7c0e23335b\build-script-build` (exit code: 1)
--- stdout
=== Running: "\\\\?\\C:\\Users\\anand\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\bin\\cargo.exe" "build" "--release" "--package" "opencv-binding-generator" "--bin" "binding-generator"
cargo:rerun-if-env-changed=OPENCV4_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=OPENCV4_STATIC
cargo:rerun-if-env-changed=OPENCV4_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=OPENCV_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=OPENCV_STATIC
cargo:rerun-if-env-changed=OPENCV_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
=== Using environment job server with the the amount of available jobs: 3
=== Crate version: Some("0.74.2")
=== Environment configuration:
=== OPENCV_PACKAGE_NAME = None
=== OPENCV_PKGCONFIG_NAME = None
=== OPENCV_CMAKE_NAME = None
=== OPENCV_CMAKE_BIN = None
=== OPENCV_VCPKG_NAME = None
=== OPENCV_LINK_LIBS = Some("opencv_world460")
=== OPENCV_LINK_PATHS = Some("C:\\tools\\opencv\\build\\x64\\vc15\\lib")
=== OPENCV_INCLUDE_PATHS = None
=== OPENCV_DISABLE_PROBES = None
=== CMAKE_PREFIX_PATH = None
=== OpenCV_DIR = None
=== PKG_CONFIG_PATH = None
=== VCPKG_ROOT = None
=== VCPKGRS_DYNAMIC = None
=== PATH = Some("F:\\LANGS\\RUST\\lvp-2\\target\\debug\\deps;F:\\LANGS\\RUST\\lvp-2\\target\\debug;C:\\Users\\anand\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib;C:\\Users\\anand\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\bin;C:\\Program Files\\WindowsApps\\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe;C:\\Python311\\Scripts\\;C:\\Python311\\;C:\\Program Files\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\dotnet\\;C:\\Program Files\\Git\\cmd;C:\\Users\\anand\\AppData\\Local\\Pub\\Cache\\bin;C:\\Program Files\\Go\\bin;C:\\Program Files\\Neovim\\/bin;C:\\Program Files\\kotlinc\\bin;C:\\Program Files\\GitHub CLI\\;C:\\Program Files\\CMake\\bin;C:\\src\\vcpkg;C:\\Program Files (x86)\\Lua\\5.1;C:\\Program Files (x86)\\Lua\\5.1\\clibs;C:\\Program Files\\nodejs\\;C:\\ProgramData\\chocolatey\\bin;C:\\Go\\bin;C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance Toolkit\\;C:\\Program Files\\Git\\bin\\git.exe;C:\\Program Files\\Git\\cmd;C:\\Program Files\\LLVM\\bin;C:\\Users\\anand\\scoop\\apps\\yarn\\current\\global\\node_modules\\.bin;C:\\Users\\anand\\scoop\\apps\\yarn\\current\\bin;C:\\Users\\anand\\scoop\\shims;C:\\Users\\anand\\AppData\\Local\\pnpm;C:\\Program Files\\MySQL\\MySQL Shell 8.0\\bin\\;C:\\Users\\anand\\.cargo\\bin;C:\\Program Files\\Conan\\conan;C:\\Users\\anand\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\MinGW\\bin;C:\\src\\flutter\\bin;C:\\Users\\anand\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\anand\\.dotnet\\tools;C:\\Users\\anand\\AppData\\Local\\Programs\\oh-my-posh\\bin;C:\\Users\\anand\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\anand\\spicetify-cli;C:\\Users\\anand\\.dotnet\\tools;C:\\Users\\anand\\go\\bin;C:\\Program Files\\JetBrains\\IntelliJ IDEA 2022.2\\bin;C:\\Users\\anand\\.dotnet\\tools;C:\\Users\\anand\\.dotnet\\tools;C:\\ghcup\\bin;C:\\Users\\anand\\AppData\\Local\\gitkraken\\bin;C:\\Users\\anand\\AppData\\Local\\JetBrains\\Toolbox\\scripts;C:\\Users\\anand\\.dotnet\\tools;C:\\Users\\anand\\AppData\\Roaming\\npm")
=== Enabled features:
=== ALPHAMAT
=== ARUCO
=== ARUCO_DETECTOR
=== BARCODE
=== BGSEGM
=== BIOINSPIRED
=== CALIB3D
=== CCALIB
=== CUDAARITHM
=== CUDABGSEGM
=== CUDACODEC
=== CUDAFEATURES2D
=== CUDAFILTERS
=== CUDAIMGPROC
=== CUDAOBJDETECT
=== CUDAOPTFLOW
=== CUDASTEREO
=== CUDAWARPING
=== CVV
=== DEFAULT
=== DNN
=== DNN_SUPERRES
=== DPM
=== FACE
=== FEATURES2D
=== FLANN
=== FREETYPE
=== FUZZY
=== GAPI
=== HDF
=== HFS
=== HIGHGUI
=== IMGCODECS
=== IMGPROC
=== IMG_HASH
=== INTENSITY_TRANSFORM
=== LINE_DESCRIPTOR
=== MCC
=== ML
=== OBJDETECT
=== OPTFLOW
=== OVIS
=== PHASE_UNWRAPPING
=== PHOTO
=== PLOT
=== QUALITY
=== RAPID
=== RGBD
=== SALIENCY
=== SFM
=== SHAPE
=== STEREO
=== STITCHING
=== STRUCTURED_LIGHT
=== SUPERRES
=== SURFACE_MATCHING
=== TEXT
=== TRACKING
=== VIDEO
=== VIDEOIO
=== VIDEOSTAB
=== VIZ
=== WECHAT_QRCODE
=== XFEATURES2D
=== XIMGPROC
=== XOBJDETECT
=== XPHOTO
=== Detected probe priority based on environment vars: pkg_config: false, cmake: false, vcpkg: true
=== Probing the OpenCV library in the following order: environment, vcpkg_cmake, vcpkg, pkg_config, cmake
=== Can't probe using: environment, continuing with other methods because: Some environment variables are missing
=== Probing OpenCV library using vcpkg_cmake
=== Can't probe using: vcpkg_cmake, continuing with other methods because: The system cannot find the file specified. (os error 2)
=== Probing OpenCV library using vcpkg
=== Can't probe using: vcpkg, continuing with other methods because: Could not find Vcpkg tree: Could not find Vcpkg root at C:\src\vcpkg\.vcpkg-root, Could not find Vcpkg tree: Could not find Vcpkg root at C:\src\vcpkg\.vcpkg-root
=== Probing OpenCV library using pkg_config
=== Can't probe using: pkg_config, continuing with other methods because: `"pkg-config" "--libs" "--cflags" "opencv4"` did not exit successfully: exit code: 1
error: could not find system library 'opencv4' required by the 'opencv' crate
--- stderr
Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv4' found
, `"pkg-config" "--libs" "--cflags" "opencv"` did not exit successfully: exit code: 1
error: could not find system library 'opencv' required by the 'opencv' crate
--- stderr
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
=== Probing OpenCV library using cmake
=== cmake ninja probe command: "cmake" "-S" "C:\\Users\\anand\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\opencv-0.74.2\\cmake" "-DOCVRS_PACKAGE_NAME=OpenCV" "-DCMAKE_BUILD_TYPE=Debug" "-G" "Ninja"
=== Probing with cmake ninja generator failed, will try Makefile generator, error: cmake returned an error
stdout: "-- Configuring incomplete, errors occurred!\nSee also \"F:/LANGS/RUST/lvp-2/target/debug/build/opencv-8ff75bb1da40fa14/out/cmake_probe_build/CMakeFiles/CMakeOutput.log\".\n"
stderr: "CMake Error: CMake was unable to find a build program corresponding to \"Ninja\". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.\nCMake Error: CMAKE_C_COMPILER not set, after EnableLanguage\nCMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage\n"
=== cmake makefiles probe command: "cmake" "-S" "C:\\Users\\anand\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\opencv-0.74.2\\cmake" "-DOCVRS_PACKAGE_NAME=OpenCV" "-DCMAKE_BUILD_TYPE=Debug" "-G" "Unix Makefiles"
=== Probing with cmake Makefile generator failed, will try deprecated find_package, error: cmake returned an error
stdout: "-- Configuring incomplete, errors occurred!\nSee also \"F:/LANGS/RUST/lvp-2/target/debug/build/opencv-8ff75bb1da40fa14/out/cmake_probe_build/CMakeFiles/CMakeOutput.log\".\n"
stderr: "CMake Error: CMake was unable to find a build program corresponding to \"Unix Makefiles\". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.\nCMake Error: CMAKE_C_COMPILER not set, after EnableLanguage\nCMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage\n"
=== cmake find-package compile probe command: "cmake" "-S" "C:\\Users\\anand\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\opencv-0.74.2\\cmake" "-DOCVRS_PACKAGE_NAME=OpenCV" "-DCMAKE_BUILD_TYPE=Debug" "--find-package" "-DCOMPILER_ID=GNU" "-DLANGUAGE=CXX" "-DMODE=COMPILE" "-DNAME=OpenCV"
=== Can't probe using: cmake, continuing with other methods because: cmake returned an error
stdout: "OpenCV not found.\r\n"
stderr: "CMake Error: Run 'cmake --help' for all supported options.\n"
Error: "Failed to find OpenCV package using probes: environment, vcpkg_cmake, vcpkg, pkg_config, cmake"```
Well, if you add this path to your path Environmental as below, you do not need to copy the dll.
At Window10, I installed opencv and llvm using chocolaty, trying to run simple example:
With Toml as:
But I got the below error: