Help: How I convert *mut *mut u8 to a Mat?
moyang628 opened this issue · comments
moyang628 commented
this is a camera scanner sdk demo.
It get pic and info from the sdk,the pic data is a jpeg format array pointer.
I try to convert the data into a Mat. but i try to save it as a .jpg file ,it returned fail.
So,How should I to use this crate right?
the code is .
unsafe{
let p_data: *mut *mut u8 = &mut std::mem::zeroed();
let pst_frame_info: *mut hk_camera_sdk::MV_CODEREADER_IMAGE_OUT_INFO_EX2 =
&mut std::mem::zeroed();
loop {
let ret = hk_camera_sdk::MV_CODEREADER_GetOneFrameTimeoutEx2(
*handle.as_ref().unwrap(),
p_data,
pst_frame_info,
1000,
);
println!("get a frame from sdk{}", ret);
println!("the pic type is {}", pst_frame_info.as_ref().unwrap().enPixelType);
let _p_data = std::mem::transmute::<*mut *mut u8,*mut c_void>(p_data);
let mat = Mat::new_rows_cols_with_data_def(1,4096*3072, opencv::core::CV_8UC1, _p_data).unwrap();
let retcode = imgcodecs::imwrite_def("camera.jpg",&mat ).unwrap();
println!("{}",retcode); //here is a false result
}