hal_use_stream/
hal_use_stream.rs1use gxci::hal::device::*;
2use gxci::hal::base::*;
3use gxci::hal::control::analog::*;
4use gxci::hal::control::image_format::*;
5use gxci::utils::debug::print_device_info;
6use gxci::utils::extract::{extract_callback_img_buf,extract_frame_callback_param};
7use gxci::raw::gx_struct::GX_FRAME_CALLBACK_PARAM;
8use gxci::opencv::{core, highgui};
9
10
11extern "C" fn frame_callback(p_frame_callback_data: *mut GX_FRAME_CALLBACK_PARAM) {
12
13 let frame_callback_data = extract_frame_callback_param(p_frame_callback_data);
14 let data = extract_callback_img_buf(frame_callback_data);
15
16 let mat = core::Mat::new_rows_cols_with_data(
17 frame_callback_data.nHeight,
18 frame_callback_data.nWidth,
19 data
20 ).unwrap();
21
22 highgui::imshow("Camera Frame", &mat).unwrap();
23 if highgui::wait_key(10).unwrap() > 0 {
24 highgui::destroy_window("Camera Frame").unwrap();
25 }
26}
27
28fn main()->Result<()> {
29 gxci_init_default()?;
30
31 let device_num = gxi_count_devices( 1000)?;
32 println!("Device number: {}", device_num);
33
34 let base_info = gxi_list_devices()?;
35 for device in &base_info {
36 print_device_info(&device);
37 }
38
39
40 gxi_open_device()?;
41
42 let max_h = gxi_get_max_height()?;
43 let max_w = gxi_get_max_width()?;
44
45 gxi_set_height(max_h)?;
46 gxi_set_width(max_w)?;
47
48
49 gxi_set_gain_auto_continuous()?;
50
51 gxi_use_stream(frame_callback)?;
54
55 gxi_close_device()?;
56
57 gxci_close()?;
58
59 Ok(())
60}