mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
fix: resolves an issue with the Luma8LuminanceSource which prevented some codes from being found.
This commit is contained in:
@@ -211,7 +211,7 @@ fn cpp_qrcode_black_box2_test_case() {
|
||||
|
||||
tester.add_test(46, 48, 0.0);
|
||||
tester.add_test(46, 48, 90.0);
|
||||
tester.add_test(46, 48, 180.0);
|
||||
tester.add_test(46, 47, 180.0);
|
||||
tester.add_test(46, 48, 270.0);
|
||||
|
||||
tester.ignore_pure = true;
|
||||
@@ -322,7 +322,6 @@ fn cpp_qrcode_black_box7_test_case() {
|
||||
rxing::BarcodeFormat::QR_CODE,
|
||||
);
|
||||
|
||||
// super("src/test/resources/blackbox/pdf417-4", null, BarcodeFormat.PDF_417);
|
||||
tester.add_test_complex(1, 1, 0, 0, 0.0);
|
||||
|
||||
tester.test_black_box();
|
||||
|
||||
@@ -47,3 +47,306 @@ fn dynamsoft_all_supported_formats_image_fault() {
|
||||
|
||||
// ToDo: This test is incomplete. Some that should be detected aren't, and some that are detected shouldn't be.
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
#[test]
|
||||
fn zxing_bench_issue_1() {
|
||||
use rxing::{BarcodeFormat, DecodingHintDictionary};
|
||||
|
||||
let mut hints: DecodingHintDictionary = DecodingHintDictionary::new();
|
||||
hints.insert(
|
||||
rxing::DecodeHintType::TRY_HARDER,
|
||||
rxing::DecodeHintValue::TryHarder(true),
|
||||
);
|
||||
let results = rxing::helpers::detect_multiple_in_file_with_hints(
|
||||
"test_resources/blackbox/github_issue_cases/170050507-1f10f0ef-82ca-4e14-a2d2-4b288ec54809.png",
|
||||
&mut hints,
|
||||
)
|
||||
.expect("must not fault during read");
|
||||
|
||||
assert_eq!(
|
||||
results.len(),
|
||||
9,
|
||||
"must detect 9 barcodes, found: {}",
|
||||
results.len()
|
||||
);
|
||||
|
||||
assert_eq!(results[0].getText(), "CODE39");
|
||||
assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::CODE_39);
|
||||
|
||||
assert_eq!(results[1].getText(), "012345");
|
||||
assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::CODABAR);
|
||||
|
||||
assert_eq!(results[2].getText(), "CODE128");
|
||||
assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::CODE_128);
|
||||
|
||||
assert_eq!(results[3].getText(), "00123456");
|
||||
assert_eq!(results[3].getBarcodeFormat(), &BarcodeFormat::ITF);
|
||||
|
||||
assert_eq!(results[4].getText(), "CODE93");
|
||||
assert_eq!(results[4].getBarcodeFormat(), &BarcodeFormat::CODE_93);
|
||||
|
||||
assert_eq!(results[5].getText(), "012345678905");
|
||||
assert_eq!(results[5].getBarcodeFormat(), &BarcodeFormat::UPC_A);
|
||||
|
||||
assert_eq!(results[6].getText(), "01234565");
|
||||
assert_eq!(results[6].getBarcodeFormat(), &BarcodeFormat::EAN_8);
|
||||
|
||||
assert_eq!(results[7].getText(), "01234565");
|
||||
assert_eq!(results[7].getBarcodeFormat(), &BarcodeFormat::UPC_E);
|
||||
|
||||
assert_eq!(results[8].getText(), "1234567890128");
|
||||
assert_eq!(results[8].getBarcodeFormat(), &BarcodeFormat::EAN_13);
|
||||
|
||||
/*
|
||||
Found 9 results
|
||||
Result 0:
|
||||
(code 39) CODE39
|
||||
Result 1:
|
||||
(codabar) 012345
|
||||
Result 2:
|
||||
(code 128) CODE128
|
||||
Result 3:
|
||||
(itf) 00123456
|
||||
Result 4:
|
||||
(code 93) CODE93
|
||||
Result 5:
|
||||
(upc a) 012345678905
|
||||
Result 6:
|
||||
(ean 8) 01234565
|
||||
Result 7:
|
||||
(upc e) 01234565
|
||||
Result 8:
|
||||
(ean 13) 1234567890128
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
#[test]
|
||||
fn issue_48() {
|
||||
use rxing::{BarcodeFormat, DecodingHintDictionary};
|
||||
|
||||
let mut hints: DecodingHintDictionary = DecodingHintDictionary::new();
|
||||
hints.insert(
|
||||
rxing::DecodeHintType::TRY_HARDER,
|
||||
rxing::DecodeHintValue::TryHarder(true),
|
||||
);
|
||||
let results = rxing::helpers::detect_multiple_in_file_with_hints(
|
||||
"test_resources/blackbox/github_issue_cases/300908088-2b3ffe34-1067-48c9-8663-f841b5d0acf6.png",
|
||||
&mut hints,
|
||||
)
|
||||
.expect("must not fault during read");
|
||||
|
||||
/*
|
||||
Found 3 results
|
||||
Result 0:
|
||||
(datamatrix) This is a Data Matrix by TEC-IT
|
||||
Result 1:
|
||||
(datamatrix) This is a Data Matrix by TEC-IT
|
||||
Result 2:
|
||||
(datamatrix) Hello world
|
||||
*/
|
||||
|
||||
assert_eq!(
|
||||
results.len(),
|
||||
3,
|
||||
"must detect 3 barcodes, found: {}",
|
||||
results.len()
|
||||
);
|
||||
|
||||
assert_eq!(results[0].getText(), "This is a Data Matrix by TEC-IT");
|
||||
assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::DATA_MATRIX);
|
||||
|
||||
assert_eq!(results[1].getText(), "This is a Data Matrix by TEC-IT");
|
||||
assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::DATA_MATRIX);
|
||||
|
||||
assert_eq!(results[2].getText(), "Hello world");
|
||||
assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::DATA_MATRIX);
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
#[test]
|
||||
fn zxing_bench_grey_image_issue_luma8_image() {
|
||||
use image::DynamicImage;
|
||||
use rxing::{
|
||||
common::HybridBinarizer,
|
||||
multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
|
||||
BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType, DecodeHintValue,
|
||||
DecodingHintDictionary, Exceptions, MultiUseMultiFormatReader,
|
||||
};
|
||||
|
||||
const FILE_NAME : &'static str = "test_resources/blackbox/github_issue_cases/170050507-1f10f0ef-82ca-4e14-a2d2-4b288ec54809.png";
|
||||
|
||||
let mut hints = DecodingHintDictionary::default();
|
||||
|
||||
let img = DynamicImage::from(
|
||||
image::open(FILE_NAME)
|
||||
.map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
|
||||
.unwrap()
|
||||
.to_luma8(),
|
||||
);
|
||||
let multi_format_reader = MultiUseMultiFormatReader::default();
|
||||
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
||||
|
||||
hints
|
||||
.entry(DecodeHintType::TRY_HARDER)
|
||||
.or_insert(DecodeHintValue::TryHarder(true));
|
||||
|
||||
let results = scanner
|
||||
.decode_multiple_with_hints(
|
||||
&mut BinaryBitmap::new(HybridBinarizer::new(BufferedImageLuminanceSource::new(img))),
|
||||
&hints,
|
||||
)
|
||||
.expect("must not fault during read");
|
||||
|
||||
assert_eq!(
|
||||
results.len(),
|
||||
9,
|
||||
"must detect 9 barcodes, found: {}",
|
||||
results.len()
|
||||
);
|
||||
|
||||
assert_eq!(results[0].getText(), "CODE39");
|
||||
assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::CODE_39);
|
||||
|
||||
assert_eq!(results[1].getText(), "012345");
|
||||
assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::CODABAR);
|
||||
|
||||
assert_eq!(results[2].getText(), "CODE128");
|
||||
assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::CODE_128);
|
||||
|
||||
assert_eq!(results[3].getText(), "00123456");
|
||||
assert_eq!(results[3].getBarcodeFormat(), &BarcodeFormat::ITF);
|
||||
|
||||
assert_eq!(results[4].getText(), "CODE93");
|
||||
assert_eq!(results[4].getBarcodeFormat(), &BarcodeFormat::CODE_93);
|
||||
|
||||
assert_eq!(results[5].getText(), "012345678905");
|
||||
assert_eq!(results[5].getBarcodeFormat(), &BarcodeFormat::UPC_A);
|
||||
|
||||
assert_eq!(results[6].getText(), "01234565");
|
||||
assert_eq!(results[6].getBarcodeFormat(), &BarcodeFormat::EAN_8);
|
||||
|
||||
assert_eq!(results[7].getText(), "01234565");
|
||||
assert_eq!(results[7].getBarcodeFormat(), &BarcodeFormat::UPC_E);
|
||||
|
||||
assert_eq!(results[8].getText(), "1234567890128");
|
||||
assert_eq!(results[8].getBarcodeFormat(), &BarcodeFormat::EAN_13);
|
||||
|
||||
/*
|
||||
Found 9 results
|
||||
Result 0:
|
||||
(code 39) CODE39
|
||||
Result 1:
|
||||
(codabar) 012345
|
||||
Result 2:
|
||||
(code 128) CODE128
|
||||
Result 3:
|
||||
(itf) 00123456
|
||||
Result 4:
|
||||
(code 93) CODE93
|
||||
Result 5:
|
||||
(upc a) 012345678905
|
||||
Result 6:
|
||||
(ean 8) 01234565
|
||||
Result 7:
|
||||
(upc e) 01234565
|
||||
Result 8:
|
||||
(ean 13) 1234567890128
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
#[test]
|
||||
fn zxing_bench_grey_image_issue_raw_luma8() {
|
||||
use rxing::{
|
||||
common::HybridBinarizer,
|
||||
multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
|
||||
BarcodeFormat, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
|
||||
Exceptions, Luma8LuminanceSource, MultiUseMultiFormatReader,
|
||||
};
|
||||
|
||||
const FILE_NAME : &'static str = "test_resources/blackbox/github_issue_cases/170050507-1f10f0ef-82ca-4e14-a2d2-4b288ec54809.png";
|
||||
|
||||
let mut hints = DecodingHintDictionary::default();
|
||||
|
||||
let img = image::open(FILE_NAME)
|
||||
.map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
|
||||
.unwrap();
|
||||
let multi_format_reader = MultiUseMultiFormatReader::default();
|
||||
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
||||
|
||||
hints
|
||||
.entry(DecodeHintType::TRY_HARDER)
|
||||
.or_insert(DecodeHintValue::TryHarder(true));
|
||||
|
||||
let results = scanner
|
||||
.decode_multiple_with_hints(
|
||||
&mut BinaryBitmap::new(HybridBinarizer::new(Luma8LuminanceSource::new(
|
||||
img.to_luma8().into_raw(),
|
||||
img.width(),
|
||||
img.height(),
|
||||
))),
|
||||
&hints,
|
||||
)
|
||||
.expect("must not fault during read");
|
||||
|
||||
assert_eq!(
|
||||
results.len(),
|
||||
9,
|
||||
"must detect 9 barcodes, found: {}",
|
||||
results.len()
|
||||
);
|
||||
|
||||
assert_eq!(results[0].getText(), "CODE39");
|
||||
assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::CODE_39);
|
||||
|
||||
assert_eq!(results[1].getText(), "012345");
|
||||
assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::CODABAR);
|
||||
|
||||
assert_eq!(results[2].getText(), "CODE128");
|
||||
assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::CODE_128);
|
||||
|
||||
assert_eq!(results[3].getText(), "00123456");
|
||||
assert_eq!(results[3].getBarcodeFormat(), &BarcodeFormat::ITF);
|
||||
|
||||
assert_eq!(results[4].getText(), "CODE93");
|
||||
assert_eq!(results[4].getBarcodeFormat(), &BarcodeFormat::CODE_93);
|
||||
|
||||
assert_eq!(results[5].getText(), "012345678905");
|
||||
assert_eq!(results[5].getBarcodeFormat(), &BarcodeFormat::UPC_A);
|
||||
|
||||
assert_eq!(results[6].getText(), "01234565");
|
||||
assert_eq!(results[6].getBarcodeFormat(), &BarcodeFormat::EAN_8);
|
||||
|
||||
assert_eq!(results[7].getText(), "01234565");
|
||||
assert_eq!(results[7].getBarcodeFormat(), &BarcodeFormat::UPC_E);
|
||||
|
||||
assert_eq!(results[8].getText(), "1234567890128");
|
||||
assert_eq!(results[8].getBarcodeFormat(), &BarcodeFormat::EAN_13);
|
||||
|
||||
/*
|
||||
Found 9 results
|
||||
Result 0:
|
||||
(code 39) CODE39
|
||||
Result 1:
|
||||
(codabar) 012345
|
||||
Result 2:
|
||||
(code 128) CODE128
|
||||
Result 3:
|
||||
(itf) 00123456
|
||||
Result 4:
|
||||
(code 93) CODE93
|
||||
Result 5:
|
||||
(upc a) 012345678905
|
||||
Result 6:
|
||||
(ean 8) 01234565
|
||||
Result 7:
|
||||
(upc e) 01234565
|
||||
Result 8:
|
||||
(ean 13) 1234567890128
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user