mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
slight performance improvement, detector
This commit is contained in:
@@ -70,7 +70,7 @@ fn test_error_in_parameter_locator_not_compact() {
|
||||
#[test]
|
||||
fn test_aztec_rxing_result_sample() {
|
||||
let matrix = BitMatrix::parse_strings(TEST_BARCODE, "X ", " ").expect("string parse success");
|
||||
let r = Detector::new(matrix).detect(false);
|
||||
let r = Detector::new(&matrix).detect(false);
|
||||
assert!(r.is_ok());
|
||||
let r = r.expect("result already tested as ok");
|
||||
let res = decoder::decode(&r).expect("decode success");
|
||||
@@ -114,7 +114,7 @@ fn test_error_in_parameter_locator(data: &str) {
|
||||
// dbg!(copy.to_string());
|
||||
// dbg!(make_larger(©, 3).to_string());
|
||||
// The detector doesn't seem to work when matrix bits are only 1x1. So magnify.
|
||||
let r = Detector::new(make_larger(©, 3)).detect(isMirror);
|
||||
let r = Detector::new(&make_larger(©, 3)).detect(isMirror);
|
||||
assert!(r.is_ok());
|
||||
let r = r.expect("result already tested as ok");
|
||||
assert_eq!(r.getNbLayers(), layers);
|
||||
@@ -144,14 +144,14 @@ fn test_error_in_parameter_locator(data: &str) {
|
||||
// );
|
||||
}
|
||||
// try {
|
||||
if let Err(res) = detector::Detector::new(make_larger(©, 3)).detect(false) {
|
||||
if let Err(res) = detector::Detector::new(&make_larger(©, 3)).detect(false) {
|
||||
if let Exceptions::NotFoundException(_msg) = res {
|
||||
// all ok
|
||||
} else {
|
||||
panic!("Only Exceptions::NotFoundException allowed, got {}", res);
|
||||
}
|
||||
} else {
|
||||
let r = Detector::new(make_larger(©, 3)).detect(false);
|
||||
let r = Detector::new(&make_larger(©, 3)).detect(false);
|
||||
assert!(r.is_ok());
|
||||
let r = r.expect("result already tested as ok");
|
||||
assert_eq!(r.getNbLayers(), layers);
|
||||
|
||||
@@ -51,7 +51,7 @@ impl Reader for AztecReader {
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
// let notFoundException = None;
|
||||
// let formatException = None;
|
||||
let mut detector = Detector::new(image.getBlackMatrix().clone());
|
||||
let mut detector = Detector::new(image.getBlackMatrix());
|
||||
let points;
|
||||
let decoderRXingResult: DecoderRXingResult;
|
||||
// try {
|
||||
|
||||
@@ -42,8 +42,8 @@ const EXPECTED_CORNER_BITS: [u32; 4] = [
|
||||
* @author David Olivier
|
||||
* @author Frank Yellin
|
||||
*/
|
||||
pub struct Detector {
|
||||
image: BitMatrix,
|
||||
pub struct Detector<'a> {
|
||||
image: &'a BitMatrix,
|
||||
|
||||
compact: bool,
|
||||
nb_layers: u32,
|
||||
@@ -52,9 +52,9 @@ pub struct Detector {
|
||||
shift: u32,
|
||||
}
|
||||
|
||||
impl Detector {
|
||||
pub fn new(image: BitMatrix) -> Self {
|
||||
Self {
|
||||
impl<'a> Detector<'_> {
|
||||
pub fn new(image: &'a BitMatrix) -> Detector<'a> {
|
||||
Detector {
|
||||
image,
|
||||
compact: false,
|
||||
nb_layers: 0,
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Reader for DataMatrixReader {
|
||||
decoderRXingResult = DECODER.decode(&bits)?;
|
||||
points.clear();
|
||||
} else {
|
||||
let detectorRXingResult = Detector::new(image.getBlackMatrix().clone())?.detect()?;
|
||||
let detectorRXingResult = Detector::new(image.getBlackMatrix())?.detect()?;
|
||||
decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?;
|
||||
points = detectorRXingResult.getPoints().clone();
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@ use super::DatamatrixDetectorResult;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct Detector {
|
||||
image: BitMatrix,
|
||||
pub struct Detector<'a> {
|
||||
image: &'a BitMatrix,
|
||||
rectangleDetector: WhiteRectangleDetector,
|
||||
}
|
||||
impl Detector {
|
||||
pub fn new(image: BitMatrix) -> Result<Self, Exceptions> {
|
||||
Ok(Self {
|
||||
rectangleDetector: WhiteRectangleDetector::new_from_image(&image)?,
|
||||
impl<'a> Detector<'_> {
|
||||
pub fn new(image: &'a BitMatrix) -> Result<Detector<'a>, Exceptions> {
|
||||
Ok(Detector {
|
||||
rectangleDetector: WhiteRectangleDetector::new_from_image(image)?,
|
||||
image,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ use super::MultiFinderPatternFinder;
|
||||
* @author Sean Owen
|
||||
* @author Hannes Erven
|
||||
*/
|
||||
pub struct MultiDetector(Detector);
|
||||
impl MultiDetector {
|
||||
pub fn new(image: BitMatrix) -> Self {
|
||||
Self(Detector::new(image))
|
||||
pub struct MultiDetector<'a>(Detector<'a>);
|
||||
impl<'a> MultiDetector<'_> {
|
||||
pub fn new(image: &'a BitMatrix) -> MultiDetector<'a> {
|
||||
MultiDetector(Detector::new(image))
|
||||
}
|
||||
|
||||
// private static final DetectorRXingResult[] EMPTY_DETECTOR_RESULTS = new DetectorRXingResult[0];
|
||||
|
||||
@@ -50,7 +50,7 @@ impl MultipleBarcodeReader for QRCodeMultiReader {
|
||||
) -> Result<Vec<crate::RXingResult>, crate::Exceptions> {
|
||||
let mut results = Vec::new();
|
||||
let detectorRXingResults =
|
||||
MultiDetector::new(image.getBlackMatrix().clone()).detectMulti(hints)?;
|
||||
MultiDetector::new(image.getBlackMatrix()).detectMulti(hints)?;
|
||||
for detectorRXingResult in detectorRXingResults {
|
||||
let mut proc = || -> Result<(), Exceptions> {
|
||||
let decoderRXingResult = decoder::decoder::decode_bitmatrix_with_hints(
|
||||
|
||||
@@ -36,14 +36,14 @@ use super::{
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct Detector {
|
||||
image: BitMatrix,
|
||||
pub struct Detector<'a> {
|
||||
image: &'a BitMatrix,
|
||||
resultPointCallback: Option<RXingResultPointCallback>,
|
||||
}
|
||||
|
||||
impl Detector {
|
||||
pub fn new(image: BitMatrix) -> Self {
|
||||
Self {
|
||||
impl<'a> Detector<'_> {
|
||||
pub fn new(image: &'a BitMatrix) -> Detector<'a> {
|
||||
Detector {
|
||||
image,
|
||||
resultPointCallback: None,
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ fn test_encode_decode(value: &str) {
|
||||
let byt_matrix = qr_code.getMatrix().as_ref().unwrap().clone();
|
||||
// dbg!(BitMatrix::from(byt_matrix.clone()).to_string());
|
||||
// let mut detector = Detector::new(make_larger(&byt_matrix.into(),5));
|
||||
let mut detector = Detector::new(byt_matrix.into());
|
||||
let new_matrix : &BitMatrix = &byt_matrix.into();
|
||||
let mut detector = Detector::new(new_matrix);
|
||||
let detected_points = detector.detect().expect("must detect");
|
||||
let decoded = decoder::decode_bitmatrix(detected_points.getBits()).expect("must decode");
|
||||
assert_eq!(decoded.getText(), value);
|
||||
@@ -15,4 +15,4 @@ pub use finder_pattern_info::*;
|
||||
pub use qrcode_detector_result::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod cetector_test;
|
||||
mod detector_test;
|
||||
|
||||
@@ -67,7 +67,7 @@ impl Reader for QRCodeReader {
|
||||
points = Vec::new();
|
||||
} else {
|
||||
let detectorRXingResult =
|
||||
Detector::new(image.getBlackMatrix().clone()).detect_with_hints(&hints)?;
|
||||
Detector::new(image.getBlackMatrix()).detect_with_hints(&hints)?;
|
||||
decoderRXingResult =
|
||||
decoder::decode_bitmatrix_with_hints(detectorRXingResult.getBits(), &hints)?;
|
||||
points = detectorRXingResult.getPoints().clone();
|
||||
|
||||
Reference in New Issue
Block a user