From 2f429a1617efe8278777941158215e8604de711b Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Thu, 5 Jan 2023 11:36:20 -0600 Subject: [PATCH] revised readme with helpers --- README.md | 33 +++------------------------------ src/helpers.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 06606d4..7e49c22 100644 --- a/README.md +++ b/README.md @@ -31,47 +31,20 @@ The library has only been thurougly tested with the `BufferedImageLuminanceSourc source is currently experimental and may result in unexpected or undefined outputs. This means that the feature flag used to enable the use of the `image` crate is currently on by default. Turning it off may result in unexpected results. -## Example +## Example with helpers ``` -use std::{cell::RefCell, collections::HashMap, rc::Rc}; - -use rxing::multi::MultipleBarcodeReader; - -use image; - use rxing; fn main() { - let file_name = "test_image.jpeg"; + let file_name = "test_image.jpg"; - let img = image::open(file_name).unwrap(); - // let img = img.resize(768, 1024, image::imageops::FilterType::Gaussian); - - let mut hints: rxing::DecodingHintDictionary = HashMap::new(); - hints.insert( - rxing::DecodeHintType::TRY_HARDER, - rxing::DecodeHintValue::TryHarder(true), - ); - - let multi_format_reader = rxing::MultiFormatReader::default(); - let mut scanner = rxing::multi::GenericMultipleBarcodeReader::new(multi_format_reader); - let results = scanner - .decode_multiple_with_hints( - &mut rxing::BinaryBitmap::new(Rc::new(RefCell::new( - rxing::common::HybridBinarizer::new(Box::new( - rxing::BufferedImageLuminanceSource::new(img), - )), - ))), - &hints, - ) - .expect("decodes"); + let results = rxing::helpers::detect_multiple_in_file(file_name).expect("decodes"); for result in results { println!("{} -> {}", result.getBarcodeFormat(), result.getText()) } } - ``` ## Latest Release Notes diff --git a/src/helpers.rs b/src/helpers.rs index 9553758..7df51a1 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,3 +1,19 @@ +/// helper functions for common decode scenarios +/// ## Eample +/// ``` +/// use rxing; +/// +/// fn main() { +/// let file_name = "test_image.jpg"; +/// +/// let results = rxing::helpers::detect_multiple_in_file(file_name).expect("decodes"); +/// +/// for result in results { +/// println!("{} -> {}", result.getBarcodeFormat(), result.getText()) +/// } +/// } +/// ``` + use std::{ collections::{HashMap, HashSet}, rc::Rc,