From 7de5440484842c147944ae123fa689333846dde7 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Wed, 23 Sep 2020 16:01:31 +0200 Subject: [PATCH] xml file is now a argument for the lib --- Cargo.lock | 1 + Cargo.toml | 3 ++- src/lib.rs | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7fa25b..dc77e92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2416,6 +2416,7 @@ name = "visual_haarcascades" version = "0.1.0" dependencies = [ "image 0.23.4", + "libc", "log", "nannou", "ndarray", diff --git a/Cargo.toml b/Cargo.toml index 4dd50a0..5d6b83c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,4 +31,5 @@ simplelog = "0.8.0" # rscam = "0.5.5" roxmltree = "0.13.0" ndarray = "0.13" -stopwatch = "0.0.7" \ No newline at end of file +stopwatch = "0.0.7" +libc = "*" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 325d9a6..6d16404 100644 --- a/src/lib.rs +++ b/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) }