nebgnahz / cv-rs

Rust wrapper for OpenCV (manual at this point)
https://nebgnahz.github.io/cv-rs/cv/
MIT License
204 stars 41 forks source link

Faild to compile on macOS #91

Closed tubo28 closed 5 years ago

tubo28 commented 6 years ago

I tried to build a sample program after brew install opencv on Mac OS X, but following error occurred. As cargo:warning=native/text.h:6:10: fatal error: 'opencv2/text/ocr.hpp' file not found shows, there is no text directory in /usr/local/include/opencv2.

Please tell me how to fix it.

src/main.rs:

// This resembles the OpenCV read image example code:
// http://docs.opencv.org/3.1.0/db/deb/tutorial_display_image.html
extern crate cv;
use cv::highgui::*;
use cv::imgcodecs::ImageReadMode;
use cv::*;

fn main() {
    let args: Vec<_> = std::env::args().collect();
    if args.len() != 2 {
        println!("Usage: display_image ImageToLoadAndDisplay");
        std::process::exit(-1);
    }

    let mat = Mat::from_path(&args[1], ImageReadMode::Color).expect("Failed to read from path");

    if !mat.is_valid() {
        println!("Could not open or find the image");
        std::process::exit(-1);
    }

    // highgui_named_window("Display window", WindowFlag::Normal).unwrap();
    mat.show("Display window", 0).unwrap();
}

Build result:

$ cargo build
   Compiling cv v0.2.2 (https://github.com/nebgnahz/cv-rs.git#bdbca2f3)
error: failed to run custom build command for `cv v0.2.2 (https://github.com/nebgnahz/cv-rs.git#bdbca2f3)`
process didn't exit successfully: `/Users/tubo28/workspace/cv/target/debug/build/cv-b84814058e46d107/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/objdetect.o" "-c" "native/objdetect.cc"
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/highgui.o" "-c" "native/highgui.cc"
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
TARGET = Some("x86_64-apple-darwin")
HOST_CXXFLAGS = None
HOST = Some("x86_64-apple-darwin")
CXXFLAGS = None
CXX_x86_64-apple-darwin = None
DEBUG = Some("true")
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/utils.o" "-c" "native/utils.cc"
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/hash.o" "-c" "native/hash.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/video.o" "-c" "native/video.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/imgproc.o" "-c" "native/imgproc.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/common-rust.o" "-c" "native/common-rust.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/mat.o" "-c" "native/mat.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/imcodecs.o" "-c" "native/imcodecs.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/text.o" "-c" "native/text.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/videoio.o" "-c" "native/videoio.cc"
exit code: 0
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXX_x86_64-apple-darwin = None
CXX_x86_64_apple_darwin = None
HOST_CXX = None
CXX = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CXXFLAGS_x86_64-apple-darwin = None
CXXFLAGS_x86_64_apple_darwin = None
HOST_CXXFLAGS = None
CXXFLAGS = None
DEBUG = Some("true")
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/features2d.o" "-c" "native/features2d.cc"
cargo:warning=In file included from native/text.cc:1:
cargo:warning=native/text.h:6:10: fatal error: 'opencv2/text/ocr.hpp' file not found
cargo:warning=#include <opencv2/text/ocr.hpp>
cargo:warning=         ^~~~~~~~~~~~~~~~~~~~~~
cargo:warning=1 error generated.
exit code: 1
exit code: 0
exit code: 0
exit code: 0

--- stderr
thread 'main' panicked at '

Internal error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "native" "-I" "/usr/local/include" "-Wall" "-Wextra" "--std=c++11" "-o" "/Users/tubo28/workspace/cv/target/debug/build/cv-b68f90c937b655a0/out/native/text.o" "-c" "native/text.cc" with args "c++" did not execute successfully (status code exit code: 1).

', /Users/tubo28/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.22/src/lib.rs:2242:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
             at libstd/panicking.rs:511
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:426
   6: std::panicking::try::do_call
             at libstd/panicking.rs:413
   7: cc::fail
             at /Users/tubo28/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.22/src/lib.rs:2242
   8: cc::Build::try_compile::{{closure}}
             at /Users/tubo28/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.22/src/lib.rs:931
   9: build_script_build::main
             at ./build.rs:138
  10: std::rt::lang_start::{{closure}}
             at /Users/travis/build/rust-lang/rust/src/libstd/rt.rs:74
  11: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  12: panic_unwind::dwarf::eh::read_encoded_pointer
             at libpanic_unwind/lib.rs:105
  13: std::sys_common::at_exit_imp::push
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  14: std::rt::lang_start
             at /Users/travis/build/rust-lang/rust/src/libstd/rt.rs:74
  15: build_script_build::get_files::{{closure}}

OpenCV Environment:

$ brew info opencv
opencv: stable 3.4.2 (bottled)
Open source computer vision library
https://opencv.org/
/usr/local/Cellar/opencv/3.4.2 (617 files, 215.0MB) *
  Poured from bottle on 2018-08-27 at 10:39:56
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/opencv.rb
==> Dependencies
Build: cmake ✔, pkg-config ✔
Required: eigen ✔, ffmpeg ✔, jpeg ✔, libpng ✔, libtiff ✔, openexr ✔, python ✔, python@2 ✔, numpy ✔, tbb ✔
$ ls /usr/local/include/opencv2
/usr/local/include/opencv2:
aruco            dnn             img_hash             optflow               stereo                videoio
aruco.hpp        dnn.hpp         img_hash.hpp         optflow.hpp           stereo.hpp            videoio.hpp
bgsegm.hpp       dpm.hpp         imgcodecs            phase_unwrapping      stitching             videostab
bioinspired      face            imgcodecs.hpp        phase_unwrapping.hpp  stitching.hpp         videostab.hpp
bioinspired.hpp  face.hpp        imgproc              photo                 structured_light      xfeatures2d
calib3d          features2d      imgproc.hpp          photo.hpp             structured_light.hpp  xfeatures2d.hpp
calib3d.hpp      features2d.hpp  line_descriptor      plot.hpp              superres              ximgproc
ccalib           flann           line_descriptor.hpp  reg                   superres.hpp          ximgproc.hpp
ccalib.hpp       flann.hpp       ml                   rgbd                  surface_matching      xobjdetect.hpp
core             fuzzy           ml.hpp               rgbd.hpp              surface_matching.hpp  xphoto
core.hpp         fuzzy.hpp       objdetect            saliency              tracking              xphoto.hpp
core_detect.hpp  hfs.hpp         objdetect.hpp        saliency.hpp          tracking.hpp
cvconfig.h       highgui         opencv.hpp           shape                 video
datasets         highgui.hpp     opencv_modules.hpp   shape.hpp             video.hpp
Pzixel commented 6 years ago

Brew install won't work because cv-rs is currently depends on several custom modules (such as text). It won't work with brew vesion that lacks them.

You can help make it building on brew version by enabling custom features (such as text, tracking, ...) and creating a PR with them. Unfortunately I don't have mac so I'm not aware which modules are included. It shouldn't take a lot of time, but it would help other users.

If you don't, then you have to use built-in script .ci/travis_build_opencv.sh to build the correct version of opencv with all required dependencies. But I do believe it's the worse alternative.

tubo28 commented 6 years ago

It works by removing some lines and files related to OCR feature, but I don't have enough skills to make a build configuration in right way and the PR 😇 I use that version of this crate for this time...

Pzixel commented 6 years ago

Juse use cfg(text) instead of removing and everything would work.