pub fn ar_matrix_code_get_id(
image: &[u8],
xsize: i32,
ysize: i32,
vertex: &[[ARdouble; 2]; 4],
code_type: ARMatrixCodeType,
pixel_format: ARPixelFormat,
patt_ratio: f64,
id: &mut i32,
dir: &mut i32,
cf: &mut f64,
error_corrected: &mut i32,
) -> Result<(), &'static str>Expand description
Decodes a matrix (barcode) marker code from the raw frame.
This is the main entry point for barcode marker decoding. Given the four corner vertices of a detected square candidate, it:
- Calls
sample_gridto projectgrid_size × grid_sizecells from the image onto a regular grid using a homography (get_cpara). - Computes the adaptive binarisation threshold from the sampled min/max
intensity. Returns
Err("Low contrast…")if the range < 30. - Scans the four corners of the inner
dim × dimcore to detect the L-shaped locator pattern (two adjacent1-bits and one0-bit), which determines the orientation (matched_dir ∈ 0..3). - Reads the data bits from the core in the correct rotation order and
passes them to
decode_matrix_raw.
§Parameters
vertex— four[x, y]corner coordinates in ideal (undistorted) space, as produced bycrate::marker::ar_get_line.code_type— selects the square dimension (3..=6) and ECC scheme.id/dir/cf/error_corrected— output values.
§Returns
Ok(()) on successful decode. Err on low contrast, missing locator pattern,
or unsupported code_type.
§Example
use webarkitlib_rs::matrix::ar_matrix_code_get_id;
use webarkitlib_rs::types::ARMatrixCodeType;
let image = vec![0u8; 640 * 480 * 3];
let vertex = [[100.0, 100.0], [200.0, 100.0], [200.0, 200.0], [100.0, 200.0]];
let mut id = -1i32;
let mut dir = -1i32;
let mut cf = 0.0f64;
let mut err = 0i32;
if ar_matrix_code_get_id(&image, 640, 480, &vertex, ARMatrixCodeType::default(),
webarkitlib_rs::types::ARPixelFormat::RGB, 0.5,
&mut id, &mut dir, &mut cf, &mut err).is_ok() {
println!("Decoded barcode id={}, dir={}, cf={:.2}", id, dir, cf);
}