twistedfall / opencv-rust

Rust bindings for OpenCV 3 & 4
MIT License
1.96k stars 160 forks source link

Problem building project : opencv version not recognized #368

Closed ekleinpeter closed 1 year ago

ekleinpeter commented 2 years ago
  1. Operating system : Linux Ubuntu 20.04 (kernel 5.15.0-46-generic)
  2. The way you installed OpenCV: manual compilation
  3. OpenCV version : 4.6.0
  4. rustc version : 1.62.1

Hi,

I'm encountering some problems on project compilation. The output of the command 'wasm-pack build' is the following :

`[INFO]: Checking for the Wasm target... [INFO]: Compiling to Wasm... Compiling opencv v0.66.0 error: failed to run custom build command for opencv v0.66.0

Caused by: process didn't exit successfully: /home/ekleinpeter/ownCloud/Documents/Programmation/WASM/Rust/video-rppg/target/release/build/opencv-a522019812d56c66/build-script-build (exit status: 101) --- stdout running: "/home/ekleinpeter/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" "build" "--release" "--package" "opencv-binding-generator" "--bin" "binding-generator"

--- stderr === Crate version: Some("0.66.0") === 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("/opt/opencv/latest/lib") === OPENCV_LINK_PATHS = Some("/opt/opencv/latest/lib") === OPENCV_INCLUDE_PATHS = Some("/opt/opencv/latest/include/opencv4/opencv2,/opt/opencv/latest/include/opencv4/opencv2/core,/opt/opencv/latest/include/opencv4/opencv2/core/cuda") === OPENCV_DISABLE_PROBES = None === CMAKE_PREFIX_PATH = None === OpenCV_DIR = None === PKG_CONFIG_PATH = Some("/opt/opencv/latest/release/unix-install") === VCPKG_ROOT = None === VCPKGRS_DYNAMIC = None === Enabled features: === ALPHAMAT === ARUCO === 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: true, cmake: false, vcpkg: false === Probing the OpenCV library in the following order: environment, pkg_config, cmake, vcpkg_cmake, vcpkg === Configuring OpenCV library from the environment: === include_paths: /opt/opencv/latest/include/opencv4/opencv2,/opt/opencv/latest/include/opencv4/opencv2/core,/opt/opencv/latest/include/opencv4/opencv2/core/cuda === link_paths: /opt/opencv/latest/lib === link_libs: /opt/opencv/latest/lib === OpenCV library configuration: Library { include_paths: [ "/opt/opencv/latest/include/opencv4/opencv2", "/opt/opencv/latest/include/opencv4/opencv2/core", "/opt/opencv/latest/include/opencv4/opencv2/core/cuda", ], version: Version { major: 0, minor: 0, patch: 0, }, cargo_metadata: [ "cargo:rustc-link-search=/opt/opencv/latest/lib", "cargo:rustc-link-lib=latest", ], } thread 'main' panicked at 'Unsupported OpenCV version: 0.0.0, must be from 3.2, 3.4 or 4.x branch', /home/ekleinpeter/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.66.0/build.rs:338:9 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace Error: Compiling your crate to WebAssembly failed Caused by: failed to execute cargo build: exited with exit status: 101 full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown" `

Thus, it seems that the 'build.rs' script cannot correctly determine the opencv version installed. I've downloaded opencv sources from their website and manually compiled it without any errors. As it can be seen from what's above and following README procedure, I've also set up environment variables as follows : export OPENCV_INCLUDE_PATHS=/opt/opencv/latest/include/opencv4/opencv2,/opt/opencv/latest/include/opencv4/opencv2/core,/opt/opencv/latest/include/opencv4/opencv2/core/cuda export OPENCV_LINK_LIBS=/opt/opencv/latest/lib export OPENCV_LINK_PATHS=/opt/opencv/latest/lib

I honestly don't know what is going on... Thanks in advance for your help.

jb-alvarado commented 2 years ago

I was running in the same issue and could fix it by adjusting includes path to:

OPENCV_INCLUDE_PATHS="/path/to/include/opencv4"
ekleinpeter commented 2 years ago

Thanx mate. I tried that and, if it still not compiles, the error is somewhat different. I'm gonna investigate that now... Though I don't really get why adding this folder to INCLUDE_PATHS has any relevance in the first place, since it only contains the 'opencv2' folder, which is already in the path... ^^'

twistedfall commented 2 years ago

When trying to determine the installed OpenCV version the build script looks for the file "opencv2/core/version.hpp" under one of the include dirs. Can you please double check if it exists?

twistedfall commented 1 year ago

Did you manage to produce a successful build?

twistedfall commented 1 year ago

I'll close the issue for now, but feel free to reopen if you're still experiencing issues