woxtu / rust-opencv

Wrapper for OpenCV (WIP, not compilable now)
13 stars 5 forks source link

objdetect::CascadeClassifier::load fails with OpenCV Error #3

Open aleksandrpak opened 9 years ago

aleksandrpak commented 9 years ago

Here is my Cargo.toml:

[package]

name = "rust-haar"
version = "0.0.1"
authors = ["alekspak <alekspak@icloud.com>"]

[dependencies.opencv]
git="https://github.com/woxtu/rust-opencv"

Trying to run following piece of code:

extern crate opencv;

use opencv::objdetect;
use std::path::posix::Path;

fn main() {
    let face_cascade_path = "/Users/alekspak/Projects/rust-haar/cascades/haarcascade_frontalface_alt.xml";
    let face_cascade = load_cascade(face_cascade_path);
}

fn load_cascade(path_string: &str) -> objdetect::CascadeClassifier {
    match objdetect::CascadeClassifier::load(&Path::new(path_string)) {
        Ok(cascade) => cascade,
        Err(error) => panic!("Cannot load cascade file {} with error {}", path_string, error)
    }
}

I receive following error:

OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /tmp/opencv-s7yTJ5/opencv-2.4.9/modules/core/src/persistence.cpp, line 4991

haarcascade_frontalface_alt.xml file is taken from opencv github repository: https://github.com/Itseez/opencv/blob/master/data/haarcascades/haarcascade_frontalface_alt.xml

And following example is working with exact same file.

opencv is installed using brew. My OS is Mac OS Yosemite 10.10.1.

jonysy commented 9 years ago

@aleksandrpak I believe that has something to do with the deprecation of the OpenCV C API (which is what rust-opencv uses) so you should load the older xml file using the code you've written.

jonysy commented 9 years ago

@woxtu OpenCV-Java loads the new haar-cascade files without a problem. Have you worked this out?

woxtu commented 9 years ago

I suppose old format file raises this error, but I don't know the details.

Try to use /usr/local/Cellar/opencv/2.4.9/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml instead. It works well for now.

vladiim commented 9 years ago

Thanks @woxtu - that worked for me

chfakht commented 9 years ago

Hi , i'm using Ubuntu 14.04 with opencv 2.4.10 i get those errors OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /home/chfakht/opencv/opencv-2.4.10/modules/core/src/persistence.cpp, line 4991 terminate called after throwing an instance of 'cv::Exception' what(): /home/chfakht/opencv/opencv-2.4.10/modules/core/src/persistence.cpp:4991: error: (-2) The node does not represent a user object (unknown type?) in function cvRead any help ??