port: rMQR: improve pure detection of large symbols

c581d8b0bb
This commit is contained in:
Henry Schimke
2024-01-14 09:48:22 -06:00
parent 3d07788f2b
commit 1a9cc55d80
3 changed files with 22 additions and 15 deletions

View File

@@ -983,16 +983,7 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
.ok_or(Exceptions::ILLEGAL_STATE)?;
let diag_hld = diagonal.to_vec().into();
let view = PatternView::new(&diag_hld);
if !(IsPattern::<E2E, 5, 7, false>(&view, &PATTERN, None, 0.0, 0.0) != 0.0) {
return Err(Exceptions::NOT_FOUND);
}
let fpWidth = (diagonal).into_iter().sum::<u16>();
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::<E2E, 5, 7, false>(&view, &PATTERN, None, 0.0, 0.0) == 0.0 {
return Err(Exceptions::NOT_FOUND);
}
@@ -1002,10 +993,13 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
.ok_or(Exceptions::ILLEGAL_STATE)?;
let subdiagonal_hld = subdiagonal.to_vec().into();
let view = PatternView::new(&subdiagonal_hld);
if IsPattern::<E2E, 4, 4, false>(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0 {
if IsPattern::<false, 4, 4, false>(&view, &SUBPATTERN, None, 0.0, 0.0) == 0.0 {
return Err(Exceptions::NOT_FOUND);
}
let mut moduleSize: f32 =
(diagonal.iter().sum::<u16>() + subdiagonal.iter().sum::<u16>()) as f32;
// Vertical corner finder patterns
// Horizontal timing patterns
for (p, d) in [
@@ -1020,9 +1014,18 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
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::<E2E, 10, 10, false>(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0) {
if IsPattern::<E2E, 10, 10, false>(&view, &TIMINGPATTERN, None, 0.0, 0.0) == 0.0 {
return Err(Exceptions::NOT_FOUND);
}
moduleSize += timing.iter().sum::<u16>() 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<QRCodeDetectorResult> {
// 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,

View File

@@ -464,8 +464,10 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
);
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
};
}

View File

@@ -319,10 +319,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();
}
//