xml file is now a argument for the lib
This commit is contained in:
parent
9621bdc934
commit
7de5440484
3 changed files with 17 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2416,6 +2416,7 @@ name = "visual_haarcascades"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"image 0.23.4",
|
||||
"libc",
|
||||
"log",
|
||||
"nannou",
|
||||
"ndarray",
|
||||
|
|
|
@ -32,3 +32,4 @@ simplelog = "0.8.0"
|
|||
roxmltree = "0.13.0"
|
||||
ndarray = "0.13"
|
||||
stopwatch = "0.0.7"
|
||||
libc = "*"
|
16
src/lib.rs
16
src/lib.rs
|
@ -7,6 +7,9 @@ mod heatmap;
|
|||
use std::slice;
|
||||
use image;
|
||||
|
||||
use std::{ffi::CStr};
|
||||
use libc::c_char;
|
||||
|
||||
static mut IMAGENR: i32 = 0;
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -17,9 +20,18 @@ pub extern "C" fn test(x: i32) -> i32 {
|
|||
|
||||
/// partly inspired by https://bheisler.github.io/post/calling-rust-in-python/
|
||||
#[no_mangle]
|
||||
pub extern "C" fn classifier_new()
|
||||
pub extern "C" fn classifier_new(s: *const c_char)
|
||||
-> *mut visualhaar::HaarClassifier {
|
||||
let haar = visualhaar::HaarClassifier::from_xml("/home/ruben/Documents/Projecten/2020/rust/testproject/haarcascade_frontalface_alt2.xml").unwrap();
|
||||
let c_str = unsafe {
|
||||
assert!(!s.is_null());
|
||||
|
||||
CStr::from_ptr(s)
|
||||
};
|
||||
|
||||
let filename = c_str.to_str().unwrap();
|
||||
|
||||
println!("Using cascade file: {}", filename);
|
||||
let haar = visualhaar::HaarClassifier::from_xml(filename).unwrap();
|
||||
let boxed_haar = Box::new(haar);
|
||||
Box::into_raw(boxed_haar)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue