|
楼主 |
发表于 2024-10-14 21:17:47
|
显示全部楼层
四川省达州市
理论上是可以的,需要自己改rust源码,已经编译好的dll不能自定义模型么
rust源码添加函数
//载入自定义模型,初始化,识别请用classification_byte_slice
#[no_mangle]
pub extern "stdcall" fn load_model_charset(data: *const u8, len: usize, charsetdata: *const u8, charsetlen: usize) -> *mut c_void {
// Convert raw pointers to slices
let slice = unsafe { std::slice::from_raw_parts(data, len) };
let model_bytes = Vec::from(slice);
let charset = unsafe { std::slice::from_raw_parts(charsetdata, charsetlen) };
// Convert charset bytes to UTF-8 string
let charset_str_result = std::str::from_utf8(charset);
let charset_str = match charset_str_result {
Ok(s) => s,
Err(_) => {
// Handle invalid UTF-8 charset data
return std::ptr::null_mut();
}
};
// Deserialize JSON string to your charset type using serde_json
let charset_result = serde_json::from_str(charset_str);
let charset = match charset_result {
Ok(c) => c,
Err(_) => {
// Handle JSON deserialization error
return std::ptr::null_mut();
}
};
// Create Ddddocr instance
let ocr_result = Ddddocr::new(model_bytes, charset);
let c = match ocr_result {
Ok(c) => c,
Err(_) => {
// Handle Ddddocr creation error
return std::ptr::null_mut();
}
};
// Box the instance to manage memory properly
let ocr_box = Box::new(c);
// Return a raw pointer to the boxed instance
Box::into_raw(ocr_box) as *mut c_void
}
|
|