xml file is now a argument for the lib

This commit is contained in:
Ruben van de Ven 2020-09-23 16:01:31 +02:00
parent 9621bdc934
commit 7de5440484
3 changed files with 17 additions and 3 deletions

1
Cargo.lock generated
View file

@ -2416,6 +2416,7 @@ name = "visual_haarcascades"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"image 0.23.4", "image 0.23.4",
"libc",
"log", "log",
"nannou", "nannou",
"ndarray", "ndarray",

View file

@ -31,4 +31,5 @@ simplelog = "0.8.0"
# rscam = "0.5.5" # rscam = "0.5.5"
roxmltree = "0.13.0" roxmltree = "0.13.0"
ndarray = "0.13" ndarray = "0.13"
stopwatch = "0.0.7" stopwatch = "0.0.7"
libc = "*"

View file

@ -7,6 +7,9 @@ mod heatmap;
use std::slice; use std::slice;
use image; use image;
use std::{ffi::CStr};
use libc::c_char;
static mut IMAGENR: i32 = 0; static mut IMAGENR: i32 = 0;
#[no_mangle] #[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/ /// partly inspired by https://bheisler.github.io/post/calling-rust-in-python/
#[no_mangle] #[no_mangle]
pub extern "C" fn classifier_new() pub extern "C" fn classifier_new(s: *const c_char)
-> *mut visualhaar::HaarClassifier { -> *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); let boxed_haar = Box::new(haar);
Box::into_raw(boxed_haar) Box::into_raw(boxed_haar)
} }