From 9aebf3acaf19dab808220eebe3cc55914d59dcbf Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sun, 14 Jan 2024 09:48:22 -0600 Subject: [PATCH] port: rMQR: improve pure detection of large symbols https://github.com/zxing-cpp/zxing-cpp/commit/c581d8b0bbbe5862f72eda07ecb50fed5cc6bb83 --- src/qrcode/cpp_port/detector.rs | 31 +++++++++++--------- tests/common/abstract_black_box_test_case.rs | 2 ++ tests/cpp_qr_code_blackbox_tests.rs | 4 ++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/qrcode/cpp_port/detector.rs b/src/qrcode/cpp_port/detector.rs index dfd6118..56b2bde 100644 --- a/src/qrcode/cpp_port/detector.rs +++ b/src/qrcode/cpp_port/detector.rs @@ -983,16 +983,7 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { .ok_or(Exceptions::ILLEGAL_STATE)?; let diag_hld = diagonal.to_vec().into(); let view = PatternView::new(&diag_hld); - if !(IsPattern::(&view, &PATTERN, None, 0.0, 0.0) != 0.0) { - return Err(Exceptions::NOT_FOUND); - } - - let fpWidth = (diagonal).into_iter().sum::(); - let moduleSize = (fpWidth as f32) / 7.0; - let dimW = (width as f32 / moduleSize as f32).floor() as u32; - let dimH = (height as f32 / moduleSize as f32).floor() as u32; - - if !Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro) { + if IsPattern::(&view, &PATTERN, None, 0.0, 0.0) == 0.0 { return Err(Exceptions::NOT_FOUND); } @@ -1002,10 +993,13 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { .ok_or(Exceptions::ILLEGAL_STATE)?; let subdiagonal_hld = subdiagonal.to_vec().into(); let view = PatternView::new(&subdiagonal_hld); - if IsPattern::(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0 { + if IsPattern::(&view, &SUBPATTERN, None, 0.0, 0.0) == 0.0 { return Err(Exceptions::NOT_FOUND); } + let mut moduleSize: f32 = + (diagonal.iter().sum::() + subdiagonal.iter().sum::()) as f32; + // Vertical corner finder patterns // Horizontal timing patterns for (p, d) in [ @@ -1020,9 +1014,18 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { let timing: TimingPattern = cur.readPattern(None).ok_or(Exceptions::ILLEGAL_STATE)?; let timing_hld = timing.to_vec().into(); let view = PatternView::new(&timing_hld); - if !(IsPattern::(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0) { + if IsPattern::(&view, &TIMINGPATTERN, None, 0.0, 0.0) == 0.0 { return Err(Exceptions::NOT_FOUND); } + moduleSize += timing.iter().sum::() as f32; + } + + moduleSize /= (7 + 4 + 4 * 10) as f32; // fp + sub + 4 x timing + let dimW = (width as f32 / moduleSize).round() as i32; + let dimH = (height as f32 / moduleSize).round() as i32; + + if !Version::IsValidSize(point(dimW, dimH), Type::RectMicro) { + return Err(Exceptions::NOT_FOUND); } // #ifdef PRINT_DEBUG @@ -1036,8 +1039,8 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { // Now just read off the bits (this is a crop + subsample) Ok(QRCodeDetectorResult::new( image.Deflate( - dimW, - dimH, + dimW as u32, + dimH as u32, top as f32 + moduleSize / 2.0, left as f32 + moduleSize / 2.0, moduleSize, diff --git a/tests/common/abstract_black_box_test_case.rs b/tests/common/abstract_black_box_test_case.rs index 26cbb08..8bd8a31 100644 --- a/tests/common/abstract_black_box_test_case.rs +++ b/tests/common/abstract_black_box_test_case.rs @@ -464,8 +464,10 @@ impl AbstractBlackBoxTestCase { ); result = if let Ok(res) = self.barcode_reader.decode_with_hints(source, &pure_hints) { + log::fine(format!("{suffix} - read pure barcode")); Some(res) } else { + // log::fine(format!("{suffix} - could not read pure barcode")); None }; } diff --git a/tests/cpp_qr_code_blackbox_tests.rs b/tests/cpp_qr_code_blackbox_tests.rs index e0f92c8..e2bc761 100644 --- a/tests/cpp_qr_code_blackbox_tests.rs +++ b/tests/cpp_qr_code_blackbox_tests.rs @@ -333,10 +333,12 @@ fn cpp_rmqr_blackbox_test_case() { QrReader, BarcodeFormat::RECTANGULAR_MICRO_QR_CODE, ); - tester.add_test(1, 1, 0.0); + tester.add_test(2, 2, 0.0); tester.add_test(1, 1, 90.0); tester.add_test(1, 1, 180.0); tester.add_test(1, 1, 270.0); tester.test_black_box(); } + +//