Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help: How I convert *mut *mut u8 to a Mat? #542

Closed
moyang628 opened this issue Feb 8, 2024 · 0 comments
Closed

Help: How I convert *mut *mut u8 to a Mat? #542

moyang628 opened this issue Feb 8, 2024 · 0 comments

Comments

@moyang628
Copy link

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant