Add error reporting to tests

This commit is contained in:
Steve Cook
2023-03-02 00:06:30 -05:00
parent 70b1ef270f
commit d2ab7de5dd
5 changed files with 52 additions and 35 deletions

View File

@@ -119,22 +119,20 @@ impl MultiFormatReader {
&mut self, &mut self,
image: &mut BinaryBitmap<B>, image: &mut BinaryBitmap<B>,
) -> Result<RXingResult> { ) -> Result<RXingResult> {
if !self.possible_formats.is_empty() { let res = self.decode_formats(image);
if res.is_ok() {
return res;
}
if matches!(
self.hints.get(&DecodeHintType::ALSO_INVERTED),
Some(DecodeHintValue::AlsoInverted(true))
) {
// Calling all readers again with inverted image
image.get_black_matrix_mut().flip_self();
let res = self.decode_formats(image); let res = self.decode_formats(image);
if res.is_ok() { if res.is_ok() {
return res; return res;
} }
if matches!(
self.hints.get(&DecodeHintType::ALSO_INVERTED),
Some(DecodeHintValue::AlsoInverted(true))
) {
// Calling all readers again with inverted image
image.get_black_matrix_mut().flip_self();
let res = self.decode_formats(image);
if res.is_ok() {
return res;
}
}
} }
Err(Exceptions::NOT_FOUND) Err(Exceptions::NOT_FOUND)
} }

View File

@@ -105,8 +105,8 @@ pub trait OneDReader: Reader {
} }
} }
let Ok(mut result) = self.decode_row(row_number as u32, &row, &hints) else { let Ok(mut result) = self.decode_row(row_number as u32, &row, &hints) else {
continue continue
}; };
// We found our barcode // We found our barcode
if attempt == 1 { if attempt == 1 {
// But it was upside down, so note that // But it was upside down, so note that

View File

@@ -28,7 +28,9 @@ use std::rc::Rc;
use image::DynamicImage; use image::DynamicImage;
use crate::{common::GlobalHistogramBinarizer, BinaryBitmap, BufferedImageLuminanceSource, Binarizer}; use crate::{
common::GlobalHistogramBinarizer, Binarizer, BinaryBitmap, BufferedImageLuminanceSource,
};
fn getBufferedImage(fileName: &str) -> DynamicImage { fn getBufferedImage(fileName: &str) -> DynamicImage {
let path = format!("test_resources/blackbox/rssexpandedstacked-2/{fileName}"); let path = format!("test_resources/blackbox/rssexpandedstacked-2/{fileName}");
@@ -36,7 +38,9 @@ fn getBufferedImage(fileName: &str) -> DynamicImage {
image::open(path).expect("load image") image::open(path).expect("load image")
} }
pub(crate) fn getBinaryBitmap(fileName: &str) -> BinaryBitmap<GlobalHistogramBinarizer<BufferedImageLuminanceSource>> { pub(crate) fn getBinaryBitmap(
fileName: &str,
) -> BinaryBitmap<GlobalHistogramBinarizer<BufferedImageLuminanceSource>> {
let bufferedImage = getBufferedImage(fileName); let bufferedImage = getBufferedImage(fileName);
BinaryBitmap::new(GlobalHistogramBinarizer::new( BinaryBitmap::new(GlobalHistogramBinarizer::new(

View File

@@ -25,7 +25,12 @@ use std::{
}; };
use encoding::Encoding; use encoding::Encoding;
use rxing::{common::{HybridBinarizer, Result}, pdf417::PDF417RXingResultMetadata, BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType, DecodeHintValue, RXingResultMetadataType, RXingResultMetadataValue, Reader, Binarizer}; use rxing::{
common::{HybridBinarizer, Result},
pdf417::PDF417RXingResultMetadata,
BarcodeFormat, Binarizer, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType,
DecodeHintValue, RXingResultMetadataType, RXingResultMetadataValue, Reader,
};
use super::TestRXingResult; use super::TestRXingResult;
@@ -254,21 +259,23 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
// drop(f); // drop(f);
// Self::rotate_image(&image, rotation).save("test_image.png").unwrap(); // Self::rotate_image(&image, rotation).save("test_image.png").unwrap();
// } // }
match self.decode(
if let Ok(decoded) = self.decode(
&mut bitmap, &mut bitmap,
rotation, rotation,
&expected_text, &expected_text,
&expected_metadata, &expected_metadata,
false, false,
) { ) {
if decoded { Ok(decoded) => {
passed_counts[x] += 1; if decoded {
} else { passed_counts[x] += 1;
misread_counts[x] += 1; } else {
misread_counts[x] += 1;
}
}
Err(e) => {
log::fine(format!("could not read at rotation {rotation}: {e:?}"));
} }
} else {
log::fine(format!("could not read at rotation {rotation}"));
} }
// try { // try {
// if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) { // if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) {
@@ -279,20 +286,23 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
// } catch (ReaderException ignored) { // } catch (ReaderException ignored) {
// log::fine(format!("could not read at rotation {}", rotation)); // log::fine(format!("could not read at rotation {}", rotation));
// } // }
if let Ok(decoded) = self.decode( match self.decode(
&mut bitmap, &mut bitmap,
rotation, rotation,
&expected_text, &expected_text,
&expected_metadata, &expected_metadata,
true, true,
) { ) {
if decoded { Ok(decoded) => {
try_harder_counts[x] += 1; if decoded {
} else { try_harder_counts[x] += 1;
try_harder_misread_counts[x] += 1; } else {
try_harder_misread_counts[x] += 1;
}
}
Err(e) => {
log::fine(format!("could not read at rotation {rotation} w/TH: {e:?}"));
} }
} else {
log::fine(format!("could not read at rotation {rotation} w/TH"));
} }
// try { // try {
// if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) { // if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {

View File

@@ -24,7 +24,13 @@ use std::{
}; };
use encoding::Encoding; use encoding::Encoding;
use rxing::{common::{HybridBinarizer, Result}, multi::MultipleBarcodeReader, pdf417::PDF417RXingResultMetadata, BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType, DecodeHintValue, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, Binarizer}; use rxing::{
common::{HybridBinarizer, Result},
multi::MultipleBarcodeReader,
pdf417::PDF417RXingResultMetadata,
BarcodeFormat, Binarizer, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType,
DecodeHintValue, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader,
};
use super::TestRXingResult; use super::TestRXingResult;
@@ -174,8 +180,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
let rotation: f32 = self.test_rxing_results.get(x).expect("ok").get_rotation(); let rotation: f32 = self.test_rxing_results.get(x).expect("ok").get_rotation();
let rotated_image = Self::rotate_image(&image, rotation); let rotated_image = Self::rotate_image(&image, rotation);
let source = BufferedImageLuminanceSource::new(rotated_image); let source = BufferedImageLuminanceSource::new(rotated_image);
let mut bitmap = let mut bitmap = BinaryBitmap::new(HybridBinarizer::new(source));
BinaryBitmap::new(HybridBinarizer::new(source));
if let Ok(res) = if let Ok(res) =
Self::decode_pdf417(&mut bitmap, false, &mut self.barcode_reader) Self::decode_pdf417(&mut bitmap, false, &mut self.barcode_reader)