Skip to main content

ar_matrix_code_get_id

Function ar_matrix_code_get_id 

Source
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:

  1. Calls sample_grid to project grid_size × grid_size cells from the image onto a regular grid using a homography (get_cpara).
  2. Computes the adaptive binarisation threshold from the sampled min/max intensity. Returns Err("Low contrast…") if the range < 30.
  3. Scans the four corners of the inner dim × dim core to detect the L-shaped locator pattern (two adjacent 1-bits and one 0-bit), which determines the orientation (matched_dir ∈ 0..3).
  4. 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 by crate::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);
}