multi test ported does not pass

This commit is contained in:
Henry Schimke
2022-12-01 16:22:52 -06:00
parent ad9d193695
commit 0829b4b77a
5 changed files with 65 additions and 71 deletions

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2016 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.multi;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.nio.file.Path;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.BufferedImageLuminanceSource;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.RXingResult;
import com.google.zxing.common.AbstractBlackBoxTestCase;
import com.google.zxing.common.HybridBinarizer;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link MultipleBarcodeReader}.
*/
public final class MultiTestCase extends Assert {
@Test
public void testMulti() throws Exception {
// Very basic test for now
Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-1");
Path testImage = testBase.resolve("1.png");
BufferedImage image = ImageIO.read(testImage.toFile());
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader());
RXingResult[] results = reader.decodeMultiple(bitmap);
assertNotNull(results);
assertEquals(2, results.length);
assertEquals("031415926531", results[0].getText());
assertEquals(BarcodeFormat.UPC_A, results[0].getBarcodeFormat());
assertEquals("www.airtable.com/jobs", results[1].getText());
assertEquals(BarcodeFormat.QR_CODE, results[1].getBarcodeFormat());
}
}

View File

@@ -53,7 +53,7 @@ impl<T: Reader> MultipleBarcodeReader for GenericMultipleBarcodeReader<T> {
hints: &crate::DecodingHintDictionary,
) -> Result<Vec<crate::RXingResult>, crate::Exceptions> {
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() {
return Err(Exceptions::NotFoundException("".to_owned()));
}
@@ -76,9 +76,9 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
xOffset: u32,
yOffset: u32,
currentDepth: u32,
) {
) -> Result<(),Exceptions>{
if currentDepth > Self::MAX_DEPTH {
return;
return Ok(());
}
let result;
@@ -88,7 +88,9 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
// return;
//}
if let Err(Exceptions::ReaderException(_)) = result {
return;
return Ok(());
}else if result.is_err(){
return Err(result.err().unwrap())
}
let result = result.expect("must exist");
@@ -108,7 +110,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
}
if resultPoints.is_empty() {
return;
return Ok(());
}
let width = image.getWidth();
let height = image.getHeight();
@@ -145,7 +147,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
xOffset,
yOffset,
currentDepth + 1,
);
)?;
}
// Decode above barcode
if minY > Self::MIN_DIMENSION_TO_RECUR {
@@ -156,7 +158,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
xOffset,
yOffset,
currentDepth + 1,
);
)?;
}
// Decode right of barcode
if maxX < (width as f32) - Self::MIN_DIMENSION_TO_RECUR {
@@ -167,7 +169,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
xOffset + maxX as u32,
yOffset,
currentDepth + 1,
);
)?;
}
// Decode below barcode
if maxY < (height as f32) - Self::MIN_DIMENSION_TO_RECUR {
@@ -178,8 +180,9 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
xOffset,
yOffset + maxY as u32,
currentDepth + 1,
);
)?;
}
Ok(())
}
fn translateRXingResultPoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult {

View File

@@ -7,3 +7,6 @@ pub use by_quadrant_reader::*;
mod generic_multiple_barcode_reader;
pub use generic_multiple_barcode_reader::*;
#[cfg(test)]
mod multi_test_case;

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2016 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use std::{path::PathBuf, rc::Rc};
use crate::{BufferedImageLuminanceSource, BinaryBitmap, common::HybridBinarizer, MultiFormatReader, BarcodeFormat};
use super::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
/**
* Tests {@link MultipleBarcodeReader}.
*/
#[test]
fn testMulti() {
// Very basic test for now
let mut testBase = PathBuf::from("test_resources/blackbox/multi-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");
// assertNotNull(results);
assert_eq!(2, results.len());
assert_eq!("031415926531", results[0].getText());
assert_eq!(&BarcodeFormat::UPC_A, results[0].getBarcodeFormat());
assert_eq!("www.airtable.com/jobs", results[1].getText());
assert_eq!(&BarcodeFormat::QR_CODE, results[1].getBarcodeFormat());
}

View File

@@ -80,7 +80,6 @@ impl Reader for MultiFormatReader {
}
impl MultiFormatReader {
const EMPTY_READER_ARRAY: Vec<Box<dyn Reader>> = Vec::new();
/**
* Decode an image using the state set up by calling setHints() previously. Continuous scan