mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-28 05:12:34 +00:00
working (upc fails)
This commit is contained in:
@@ -53,7 +53,7 @@ impl<T: Reader> MultipleBarcodeReader for GenericMultipleBarcodeReader<T> {
|
|||||||
hints: &crate::DecodingHintDictionary,
|
hints: &crate::DecodingHintDictionary,
|
||||||
) -> Result<Vec<crate::RXingResult>, crate::Exceptions> {
|
) -> Result<Vec<crate::RXingResult>, crate::Exceptions> {
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0)?;
|
self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0);
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||||
}
|
}
|
||||||
@@ -76,28 +76,19 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
|
|||||||
xOffset: u32,
|
xOffset: u32,
|
||||||
yOffset: u32,
|
yOffset: u32,
|
||||||
currentDepth: u32,
|
currentDepth: u32,
|
||||||
) -> Result<(), Exceptions> {
|
) {
|
||||||
if currentDepth > Self::MAX_DEPTH {
|
if currentDepth > Self::MAX_DEPTH {
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result;
|
// let result;
|
||||||
//try {
|
let Ok(result) = self.0.decode_with_hints(image, hints) else {
|
||||||
result = self.0.decode_with_hints(image, hints);
|
return;
|
||||||
//} catch (ReaderException ignored) {
|
};
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
if let Err(Exceptions::ReaderException(_)) = result {
|
|
||||||
return Ok(());
|
|
||||||
} else if result.is_err() {
|
|
||||||
return Err(result.err().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = result.expect("must exist");
|
|
||||||
|
|
||||||
let mut alreadyFound = false;
|
let mut alreadyFound = false;
|
||||||
for existingRXingResult in results.iter() {
|
for existingRXingResult in results.iter() {
|
||||||
if existingRXingResult.getText() == (result.getText()) {
|
if existingRXingResult.getText() == result.getText() {
|
||||||
alreadyFound = true;
|
alreadyFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -110,8 +101,9 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resultPoints.is_empty() {
|
if resultPoints.is_empty() {
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let width = image.getWidth();
|
let width = image.getWidth();
|
||||||
let height = image.getHeight();
|
let height = image.getHeight();
|
||||||
let mut minX: f32 = width as f32;
|
let mut minX: f32 = width as f32;
|
||||||
@@ -147,7 +139,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
|
|||||||
xOffset,
|
xOffset,
|
||||||
yOffset,
|
yOffset,
|
||||||
currentDepth + 1,
|
currentDepth + 1,
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
// Decode above barcode
|
// Decode above barcode
|
||||||
if minY > Self::MIN_DIMENSION_TO_RECUR {
|
if minY > Self::MIN_DIMENSION_TO_RECUR {
|
||||||
@@ -158,7 +150,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
|
|||||||
xOffset,
|
xOffset,
|
||||||
yOffset,
|
yOffset,
|
||||||
currentDepth + 1,
|
currentDepth + 1,
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
// Decode right of barcode
|
// Decode right of barcode
|
||||||
if maxX < (width as f32) - Self::MIN_DIMENSION_TO_RECUR {
|
if maxX < (width as f32) - Self::MIN_DIMENSION_TO_RECUR {
|
||||||
@@ -169,7 +161,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
|
|||||||
xOffset + maxX as u32,
|
xOffset + maxX as u32,
|
||||||
yOffset,
|
yOffset,
|
||||||
currentDepth + 1,
|
currentDepth + 1,
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
// Decode below barcode
|
// Decode below barcode
|
||||||
if maxY < (height as f32) - Self::MIN_DIMENSION_TO_RECUR {
|
if maxY < (height as f32) - Self::MIN_DIMENSION_TO_RECUR {
|
||||||
@@ -180,9 +172,8 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
|
|||||||
xOffset,
|
xOffset,
|
||||||
yOffset + maxY as u32,
|
yOffset + maxY as u32,
|
||||||
currentDepth + 1,
|
currentDepth + 1,
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translateRXingResultPoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult {
|
fn translateRXingResultPoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult {
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{path::PathBuf, rc::Rc};
|
use std::{collections::HashSet, path::PathBuf, rc::Rc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::HybridBinarizer, BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource,
|
common::HybridBinarizer, qrcode::QRCodeReader, BarcodeFormat, BinaryBitmap,
|
||||||
MultiFormatReader,
|
BufferedImageLuminanceSource, MultiFormatReader,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
|
use super::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
|
||||||
@@ -51,3 +51,41 @@ fn testMulti() {
|
|||||||
assert_eq!("www.airtable.com/jobs", results[1].getText());
|
assert_eq!("www.airtable.com/jobs", results[1].getText());
|
||||||
assert_eq!(&BarcodeFormat::QR_CODE, results[1].getBarcodeFormat());
|
assert_eq!(&BarcodeFormat::QR_CODE, results[1].getBarcodeFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testMultiQR() {
|
||||||
|
// Very basic test for now
|
||||||
|
let mut testBase = PathBuf::from("test_resources/blackbox/multi-qrcode-1");
|
||||||
|
|
||||||
|
testBase.push("1.png");
|
||||||
|
let image = image::io::Reader::open(testBase)
|
||||||
|
.expect("image must open")
|
||||||
|
.decode()
|
||||||
|
.expect("must decode");
|
||||||
|
let source = BufferedImageLuminanceSource::new(image);
|
||||||
|
let bitmap = BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(source))));
|
||||||
|
|
||||||
|
let mut reader = GenericMultipleBarcodeReader::new(MultiFormatReader::default());
|
||||||
|
let results = reader.decodeMultiple(&bitmap).expect("must decode multi");
|
||||||
|
assert_eq!(4, results.len());
|
||||||
|
|
||||||
|
let mut barcodeContents = HashSet::new();
|
||||||
|
for result in results {
|
||||||
|
barcodeContents.insert(result.getText().to_owned());
|
||||||
|
assert_eq!(&BarcodeFormat::QR_CODE, result.getBarcodeFormat());
|
||||||
|
assert!(!result.getRXingResultMetadata().is_empty());
|
||||||
|
}
|
||||||
|
let mut expectedContents = HashSet::new();
|
||||||
|
expectedContents.insert(
|
||||||
|
"You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!"
|
||||||
|
.to_owned(),
|
||||||
|
);
|
||||||
|
expectedContents.insert(
|
||||||
|
"You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!".to_owned(),
|
||||||
|
);
|
||||||
|
expectedContents.insert(
|
||||||
|
"You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)".to_owned());
|
||||||
|
expectedContents
|
||||||
|
.insert("You get to CREATE OUR JOURNAL PROMPT FOR THE DAY! Yay! Way to go! ".to_owned());
|
||||||
|
assert_eq!(expectedContents, barcodeContents);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user