mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
move to OnceCell binarizer cache
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
//package com.google.zxing;
|
||||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc, borrow::Cow};
|
||||
|
||||
use crate::{
|
||||
common::{BitArray, BitMatrix},
|
||||
@@ -51,7 +51,7 @@ pub trait Binarizer {
|
||||
* @return The array of bits for this row (true means black).
|
||||
* @throws NotFoundException if row can't be binarized
|
||||
*/
|
||||
fn getBlackRow(&mut self, y: usize) -> Result<BitArray, Exceptions>;
|
||||
fn getBlackRow(&self, y: usize) -> Result<Cow<BitArray>, Exceptions>;
|
||||
|
||||
/**
|
||||
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
|
||||
@@ -62,7 +62,7 @@ pub trait Binarizer {
|
||||
* @return The 2D array of bits for the image (true means black).
|
||||
* @throws NotFoundException if image can't be binarized to make a matrix
|
||||
*/
|
||||
fn getBlackMatrix(&mut self) -> Result<&BitMatrix, Exceptions>;
|
||||
fn getBlackMatrix(& self) -> Result<&BitMatrix, Exceptions>;
|
||||
|
||||
/**
|
||||
* Creates a new object with the same type as this Binarizer implementation, but with pristine
|
||||
@@ -72,7 +72,7 @@ pub trait Binarizer {
|
||||
* @param source The LuminanceSource this Binarizer will operate on.
|
||||
* @return A new concrete Binarizer implementation object.
|
||||
*/
|
||||
fn createBinarizer(&self, source: Box<dyn LuminanceSource>) -> Rc<RefCell<dyn Binarizer>>;
|
||||
fn createBinarizer(&self, source: Box<dyn LuminanceSource>) -> Rc<dyn Binarizer>;
|
||||
|
||||
fn getWidth(&self) -> usize;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//package com.google.zxing;
|
||||
|
||||
use std::{cell::RefCell, fmt, rc::Rc};
|
||||
use std::{cell::RefCell, fmt, rc::Rc, borrow::Cow};
|
||||
|
||||
use crate::{
|
||||
common::{BitArray, BitMatrix},
|
||||
@@ -31,12 +31,12 @@ use crate::{
|
||||
*/
|
||||
|
||||
pub struct BinaryBitmap {
|
||||
binarizer: Rc<RefCell<dyn Binarizer>>,
|
||||
binarizer: Rc<dyn Binarizer>,
|
||||
matrix: Option<BitMatrix>,
|
||||
}
|
||||
|
||||
impl BinaryBitmap {
|
||||
pub fn new(binarizer: Rc<RefCell<dyn Binarizer>>) -> Self {
|
||||
pub fn new(binarizer: Rc<dyn Binarizer>) -> Self {
|
||||
Self {
|
||||
matrix: None,
|
||||
binarizer,
|
||||
@@ -47,14 +47,14 @@ impl BinaryBitmap {
|
||||
* @return The width of the bitmap.
|
||||
*/
|
||||
pub fn getWidth(&self) -> usize {
|
||||
return self.binarizer.borrow().getWidth();
|
||||
return self.binarizer.getWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The height of the bitmap.
|
||||
*/
|
||||
pub fn getHeight(&self) -> usize {
|
||||
return self.binarizer.borrow().getHeight();
|
||||
return self.binarizer.getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,8 +68,8 @@ impl BinaryBitmap {
|
||||
* @return The array of bits for this row (true means black).
|
||||
* @throws NotFoundException if row can't be binarized
|
||||
*/
|
||||
pub fn getBlackRow(&mut self, y: usize) -> Result<BitArray, Exceptions> {
|
||||
return self.binarizer.borrow_mut().getBlackRow(y);
|
||||
pub fn getBlackRow(& self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
||||
self.binarizer.getBlackRow(y)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,6 @@ impl BinaryBitmap {
|
||||
if self.matrix.is_none() {
|
||||
self.matrix = Some(
|
||||
self.binarizer
|
||||
.borrow_mut()
|
||||
.getBlackMatrix()
|
||||
.unwrap()
|
||||
.clone(),
|
||||
@@ -117,7 +116,6 @@ impl BinaryBitmap {
|
||||
if self.matrix.is_none() {
|
||||
self.matrix = Some(
|
||||
self.binarizer
|
||||
.borrow_mut()
|
||||
.getBlackMatrix()
|
||||
.unwrap()
|
||||
.clone(),
|
||||
@@ -130,10 +128,7 @@ impl BinaryBitmap {
|
||||
* @return Whether this bitmap can be cropped.
|
||||
*/
|
||||
pub fn isCropSupported(&self) -> bool {
|
||||
let b = self.binarizer.borrow();
|
||||
let r = b.getLuminanceSource();
|
||||
|
||||
r.isCropSupported()
|
||||
self.binarizer.getLuminanceSource().isCropSupported()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,12 +144,10 @@ impl BinaryBitmap {
|
||||
pub fn crop(&mut self, left: usize, top: usize, width: usize, height: usize) -> BinaryBitmap {
|
||||
let newSource = self
|
||||
.binarizer
|
||||
.borrow()
|
||||
.getLuminanceSource()
|
||||
.crop(left, top, width, height);
|
||||
return BinaryBitmap::new(
|
||||
self.binarizer
|
||||
.borrow()
|
||||
.createBinarizer(newSource.expect("new lum source expected")),
|
||||
);
|
||||
// Self {
|
||||
@@ -169,7 +162,6 @@ impl BinaryBitmap {
|
||||
pub fn isRotateSupported(&self) -> bool {
|
||||
return self
|
||||
.binarizer
|
||||
.borrow()
|
||||
.getLuminanceSource()
|
||||
.isRotateSupported();
|
||||
}
|
||||
@@ -183,12 +175,10 @@ impl BinaryBitmap {
|
||||
pub fn rotateCounterClockwise(&mut self) -> BinaryBitmap {
|
||||
let newSource = self
|
||||
.binarizer
|
||||
.borrow()
|
||||
.getLuminanceSource()
|
||||
.rotateCounterClockwise();
|
||||
return BinaryBitmap::new(
|
||||
self.binarizer
|
||||
.borrow()
|
||||
.createBinarizer(newSource.expect("new lum source expected")),
|
||||
);
|
||||
// let mut new_matrix = self.getBlackMatrix().clone();
|
||||
@@ -209,12 +199,10 @@ impl BinaryBitmap {
|
||||
pub fn rotateCounterClockwise45(&self) -> BinaryBitmap {
|
||||
let newSource = self
|
||||
.binarizer
|
||||
.borrow()
|
||||
.getLuminanceSource()
|
||||
.rotateCounterClockwise45();
|
||||
return BinaryBitmap::new(
|
||||
self.binarizer
|
||||
.borrow()
|
||||
.createBinarizer(newSource.expect("new lum source expected")),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
// import com.google.zxing.LuminanceSource;
|
||||
// import com.google.zxing.NotFoundException;
|
||||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc, borrow::Cow};
|
||||
|
||||
use once_cell::unsync::OnceCell;
|
||||
|
||||
use crate::{Binarizer, Exceptions, LuminanceSource};
|
||||
|
||||
@@ -42,8 +44,8 @@ pub struct GlobalHistogramBinarizer {
|
||||
width: usize,
|
||||
height: usize,
|
||||
source: Box<dyn LuminanceSource>,
|
||||
black_matrix: Option<BitMatrix>,
|
||||
black_row_cache: Vec<Option<BitArray>>,
|
||||
black_matrix: OnceCell<BitMatrix>,
|
||||
black_row_cache: Vec<OnceCell<BitArray>>,
|
||||
}
|
||||
|
||||
impl Binarizer for GlobalHistogramBinarizer {
|
||||
@@ -52,65 +54,69 @@ impl Binarizer for GlobalHistogramBinarizer {
|
||||
}
|
||||
|
||||
// Applies simple sharpening to the row data to improve performance of the 1D Readers.
|
||||
fn getBlackRow(&mut self, y: usize) -> Result<BitArray, Exceptions> {
|
||||
if let Some(black_row) = &self.black_row_cache[y] {
|
||||
return Ok(black_row.clone());
|
||||
}
|
||||
let source = self.getLuminanceSource();
|
||||
let width = source.getWidth();
|
||||
let mut row = BitArray::with_size(width);
|
||||
|
||||
// self.initArrays(width);
|
||||
let localLuminances = source.getRow(y);
|
||||
let mut localBuckets = [0; GlobalHistogramBinarizer::LUMINANCE_BUCKETS]; //self.buckets.clone();
|
||||
for x in 0..width {
|
||||
// for (int x = 0; x < width; x++) {
|
||||
localBuckets
|
||||
[((localLuminances[x]) >> GlobalHistogramBinarizer::LUMINANCE_SHIFT) as usize] += 1;
|
||||
}
|
||||
let blackPoint = Self::estimateBlackPoint(&localBuckets)?;
|
||||
|
||||
if width < 3 {
|
||||
// Special case for very small images
|
||||
for (x, lum) in localLuminances.iter().enumerate().take(width) {
|
||||
// for x in 0..width {
|
||||
// for (int x = 0; x < width; x++) {
|
||||
if (*lum as u32) < blackPoint {
|
||||
row.set(x);
|
||||
fn getBlackRow(& self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
||||
let row = self.black_row_cache[y].get_or_try_init(||{
|
||||
let source = self.getLuminanceSource();
|
||||
let width = source.getWidth();
|
||||
let mut row = BitArray::with_size(width);
|
||||
|
||||
// self.initArrays(width);
|
||||
let localLuminances = source.getRow(y);
|
||||
let mut localBuckets = [0; GlobalHistogramBinarizer::LUMINANCE_BUCKETS]; //self.buckets.clone();
|
||||
for x in 0..width {
|
||||
// for (int x = 0; x < width; x++) {
|
||||
localBuckets
|
||||
[((localLuminances[x]) >> GlobalHistogramBinarizer::LUMINANCE_SHIFT) as usize] += 1;
|
||||
}
|
||||
let blackPoint = Self::estimateBlackPoint(&localBuckets)?;
|
||||
|
||||
if width < 3 {
|
||||
// Special case for very small images
|
||||
for (x, lum) in localLuminances.iter().enumerate().take(width) {
|
||||
// for x in 0..width {
|
||||
// for (int x = 0; x < width; x++) {
|
||||
if (*lum as u32) < blackPoint {
|
||||
row.set(x);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut left = localLuminances[0]; // & 0xff;
|
||||
let mut center = localLuminances[1]; // & 0xff;
|
||||
for x in 1..width - 1 {
|
||||
// for (int x = 1; x < width - 1; x++) {
|
||||
let right = localLuminances[x + 1];
|
||||
// A simple -1 4 -1 box filter with a weight of 2.
|
||||
if ((center as i64 * 4) - left as i64 - right as i64) / 2 < blackPoint as i64 {
|
||||
row.set(x);
|
||||
}
|
||||
left = center;
|
||||
center = right;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut left = localLuminances[0]; // & 0xff;
|
||||
let mut center = localLuminances[1]; // & 0xff;
|
||||
for x in 1..width - 1 {
|
||||
// for (int x = 1; x < width - 1; x++) {
|
||||
let right = localLuminances[x + 1];
|
||||
// A simple -1 4 -1 box filter with a weight of 2.
|
||||
if ((center as i64 * 4) - left as i64 - right as i64) / 2 < blackPoint as i64 {
|
||||
row.set(x);
|
||||
}
|
||||
left = center;
|
||||
center = right;
|
||||
}
|
||||
}
|
||||
self.black_row_cache[y] = Some(row.clone());
|
||||
Ok(row)
|
||||
|
||||
Ok(row)
|
||||
})?;
|
||||
|
||||
Ok(Cow::Borrowed(row))
|
||||
|
||||
}
|
||||
|
||||
// Does not sharpen the data, as this call is intended to only be used by 2D Readers.
|
||||
fn getBlackMatrix(&mut self) -> Result<&BitMatrix, Exceptions> {
|
||||
if self.black_matrix.is_none() {
|
||||
self.black_matrix =
|
||||
Some(Self::build_black_matrix(&self.source).expect("matrix must generate"))
|
||||
}
|
||||
Ok(self.black_matrix.as_ref().unwrap())
|
||||
fn getBlackMatrix(& self) -> Result<&BitMatrix, Exceptions> {
|
||||
// if self.black_matrix.is_none() {
|
||||
// self.black_matrix =
|
||||
// Some(Self::build_black_matrix(&self.source).expect("matrix must generate"))
|
||||
// }
|
||||
// Ok(self.black_matrix.as_ref().unwrap())
|
||||
let matrix = self.black_matrix.get_or_try_init(||Self::build_black_matrix(&self.source))?;
|
||||
Ok(matrix)
|
||||
}
|
||||
|
||||
fn createBinarizer(
|
||||
&self,
|
||||
source: Box<dyn crate::LuminanceSource>,
|
||||
) -> Rc<RefCell<dyn Binarizer>> {
|
||||
Rc::new(RefCell::new(GlobalHistogramBinarizer::new(source)))
|
||||
) -> Rc<dyn Binarizer> {
|
||||
Rc::new(GlobalHistogramBinarizer::new(source))
|
||||
}
|
||||
|
||||
fn getWidth(&self) -> usize {
|
||||
@@ -133,8 +139,8 @@ impl GlobalHistogramBinarizer {
|
||||
_luminances: vec![0; source.getWidth()],
|
||||
width: source.getWidth(),
|
||||
height: source.getHeight(),
|
||||
black_matrix: None,
|
||||
black_row_cache: vec![None; source.getHeight()],
|
||||
black_matrix: OnceCell::new(),
|
||||
black_row_cache: vec![OnceCell::default(); source.getHeight()],
|
||||
source,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
// import com.google.zxing.LuminanceSource;
|
||||
// import com.google.zxing.NotFoundException;
|
||||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc, borrow::Cow};
|
||||
|
||||
use once_cell::unsync::OnceCell;
|
||||
|
||||
use crate::{Binarizer, Exceptions, LuminanceSource};
|
||||
|
||||
@@ -48,14 +50,14 @@ pub struct HybridBinarizer {
|
||||
//height: usize,
|
||||
//source: Box<dyn LuminanceSource>,
|
||||
ghb: GlobalHistogramBinarizer,
|
||||
black_matrix: Option<BitMatrix>,
|
||||
black_matrix: OnceCell<BitMatrix>,
|
||||
}
|
||||
impl Binarizer for HybridBinarizer {
|
||||
fn getLuminanceSource(&self) -> &Box<dyn LuminanceSource> {
|
||||
self.ghb.getLuminanceSource()
|
||||
}
|
||||
|
||||
fn getBlackRow(&mut self, y: usize) -> Result<BitArray, Exceptions> {
|
||||
fn getBlackRow(& self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
||||
self.ghb.getBlackRow(y)
|
||||
}
|
||||
|
||||
@@ -64,18 +66,20 @@ impl Binarizer for HybridBinarizer {
|
||||
* constructor instead, but there are some advantages to doing it lazily, such as making
|
||||
* profiling easier, and not doing heavy lifting when callers don't expect it.
|
||||
*/
|
||||
fn getBlackMatrix(&mut self) -> Result<&BitMatrix, Exceptions> {
|
||||
if self.black_matrix.is_none() {
|
||||
self.black_matrix = Some(
|
||||
Self::calculateBlackMatrix(&mut self.ghb)
|
||||
.expect("generate black matrix must complete"),
|
||||
)
|
||||
}
|
||||
Ok(self.black_matrix.as_ref().unwrap())
|
||||
fn getBlackMatrix(& self) -> Result<&BitMatrix, Exceptions> {
|
||||
// if self.black_matrix.is_none() {
|
||||
// self.black_matrix = Some(
|
||||
// Self::calculateBlackMatrix(&mut self.ghb)
|
||||
// .expect("generate black matrix must complete"),
|
||||
// )
|
||||
// }
|
||||
// Ok(self.black_matrix.as_ref().unwrap())
|
||||
let matrix = self.black_matrix.get_or_try_init(||Self::calculateBlackMatrix(& self.ghb))?;
|
||||
Ok(matrix)
|
||||
}
|
||||
|
||||
fn createBinarizer(&self, source: Box<dyn LuminanceSource>) -> Rc<RefCell<dyn Binarizer>> {
|
||||
Rc::new(RefCell::new(HybridBinarizer::new(source)))
|
||||
fn createBinarizer(&self, source: Box<dyn LuminanceSource>) -> Rc<dyn Binarizer> {
|
||||
Rc::new(HybridBinarizer::new(source))
|
||||
}
|
||||
|
||||
fn getWidth(&self) -> usize {
|
||||
@@ -98,12 +102,12 @@ impl HybridBinarizer {
|
||||
pub fn new(source: Box<dyn LuminanceSource>) -> Self {
|
||||
let ghb = GlobalHistogramBinarizer::new(source);
|
||||
Self {
|
||||
black_matrix: None,
|
||||
black_matrix: OnceCell::new(),
|
||||
ghb,
|
||||
}
|
||||
}
|
||||
|
||||
fn calculateBlackMatrix(ghb: &mut GlobalHistogramBinarizer) -> Result<BitMatrix, Exceptions> {
|
||||
fn calculateBlackMatrix(ghb: & GlobalHistogramBinarizer) -> Result<BitMatrix, Exceptions> {
|
||||
// let matrix;
|
||||
let source = ghb.getLuminanceSource();
|
||||
let width = source.getWidth();
|
||||
|
||||
@@ -41,9 +41,9 @@ pub fn detect_in_file_with_hints(
|
||||
.or_insert(DecodeHintValue::TryHarder(true));
|
||||
|
||||
multi_format_reader.decode_with_hints(
|
||||
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
&mut BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
BufferedImageLuminanceSource::new(img),
|
||||
))))),
|
||||
)))),
|
||||
hints,
|
||||
)
|
||||
}
|
||||
@@ -67,9 +67,9 @@ pub fn detect_multiple_in_file_with_hints(
|
||||
.or_insert(DecodeHintValue::TryHarder(true));
|
||||
|
||||
scanner.decode_multiple_with_hints(
|
||||
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
&mut BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
BufferedImageLuminanceSource::new(img),
|
||||
))))),
|
||||
)))),
|
||||
hints,
|
||||
)
|
||||
}
|
||||
@@ -104,9 +104,9 @@ pub fn detect_in_luma_with_hints(
|
||||
.or_insert(DecodeHintValue::TryHarder(true));
|
||||
|
||||
multi_format_reader.decode_with_hints(
|
||||
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
&mut BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
Luma8LuminanceSource::new(luma, width, height),
|
||||
))))),
|
||||
)))),
|
||||
hints,
|
||||
)
|
||||
}
|
||||
@@ -133,9 +133,9 @@ pub fn detect_multiple_in_luma_with_hints(
|
||||
.or_insert(DecodeHintValue::TryHarder(true));
|
||||
|
||||
scanner.decode_multiple_with_hints(
|
||||
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
&mut BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
Luma8LuminanceSource::new(luma, width, height),
|
||||
))))),
|
||||
)))),
|
||||
hints,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ fn testMulti() {
|
||||
.decode()
|
||||
.expect("must decode");
|
||||
let source = BufferedImageLuminanceSource::new(image);
|
||||
let mut bitmap = BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
let mut bitmap = BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
source,
|
||||
)))));
|
||||
))));
|
||||
|
||||
let mut reader = GenericMultipleBarcodeReader::new(MultiFormatReader::default());
|
||||
let results = reader
|
||||
@@ -67,9 +67,9 @@ fn testMultiQR() {
|
||||
.decode()
|
||||
.expect("must decode");
|
||||
let source = BufferedImageLuminanceSource::new(image);
|
||||
let mut bitmap = BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
let mut bitmap = BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
source,
|
||||
)))));
|
||||
))));
|
||||
|
||||
let mut reader = GenericMultipleBarcodeReader::new(MultiFormatReader::default());
|
||||
let results = reader
|
||||
|
||||
@@ -250,9 +250,9 @@ mod multi_qr_code_test_case {
|
||||
.decode()
|
||||
.expect("must decode");
|
||||
let source = BufferedImageLuminanceSource::new(image);
|
||||
let mut bitmap = BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
|
||||
let mut bitmap = BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(
|
||||
source,
|
||||
)))));
|
||||
))));
|
||||
|
||||
let mut reader = QRCodeMultiReader::new();
|
||||
let results = reader.decode_multiple(&mut bitmap).expect("must decode");
|
||||
|
||||
@@ -81,7 +81,7 @@ pub trait OneDReader: Reader {
|
||||
|
||||
// Estimate black point for this row and load it:
|
||||
let mut row = if let Ok(res) = image.getBlackRow(rowNumber as usize) {
|
||||
res
|
||||
res.into_owned()
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -174,9 +174,9 @@ fn assertCorrectImage2binary(fileName: &str, expected: &str) {
|
||||
let path = format!("test_resources/blackbox/rssexpanded-1/{}", fileName);
|
||||
|
||||
let image = image::open(path).expect("file exists");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
||||
))));
|
||||
)));
|
||||
let rowNumber = binaryMap.getHeight() / 2;
|
||||
let row = binaryMap.getBlackRow(rowNumber).expect("row");
|
||||
|
||||
|
||||
@@ -71,9 +71,9 @@ fn assertCorrectImage2result(fileName: &str, expected: ExpandedProductParsedRXin
|
||||
let path = format!("test_resources/blackbox/rssexpanded-1/{}", fileName);
|
||||
|
||||
let image = image::open(path).expect("image must exist");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
||||
))));
|
||||
)));
|
||||
let rowNumber = binaryMap.getHeight() / 2;
|
||||
let row = binaryMap.getBlackRow(rowNumber).expect("get row");
|
||||
|
||||
|
||||
@@ -184,9 +184,9 @@ fn assertCorrectImage2string(fileName: &str, expected: &str) {
|
||||
let path = format!("test_resources/blackbox/rssexpanded-1/{}", fileName);
|
||||
|
||||
let image = image::open(path).expect("load image");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
||||
))));
|
||||
)));
|
||||
let rowNumber = binaryMap.getHeight() / 2;
|
||||
let row = binaryMap.getBlackRow(rowNumber).expect("get row");
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ use super::RSSExpandedReader;
|
||||
#[test]
|
||||
fn testFindFinderPatterns() {
|
||||
let image = readImage("2.png");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
||||
))));
|
||||
)));
|
||||
let rowNumber = binaryMap.getHeight() as u32 / 2;
|
||||
let row = binaryMap.getBlackRow(rowNumber as usize).expect("ok");
|
||||
let mut previousPairs = Vec::new(); //new ArrayList<>();
|
||||
@@ -88,9 +88,9 @@ fn testFindFinderPatterns() {
|
||||
#[test]
|
||||
fn testRetrieveNextPairPatterns() {
|
||||
let image = readImage("3.png");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
||||
))));
|
||||
)));
|
||||
let rowNumber = binaryMap.getHeight() as u32 / 2;
|
||||
let row = binaryMap.getBlackRow(rowNumber as usize).expect("create");
|
||||
let mut previousPairs = Vec::new(); //new ArrayList<>();
|
||||
@@ -116,9 +116,9 @@ fn testRetrieveNextPairPatterns() {
|
||||
#[test]
|
||||
fn testDecodeCheckCharacter() {
|
||||
let image = readImage("3.png");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image.clone())),
|
||||
))));
|
||||
)));
|
||||
let row = binaryMap
|
||||
.getBlackRow(binaryMap.getHeight() / 2)
|
||||
.expect("create");
|
||||
@@ -144,9 +144,9 @@ fn testDecodeCheckCharacter() {
|
||||
#[test]
|
||||
fn testDecodeDataCharacter() {
|
||||
let image = readImage("3.png");
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image.clone())),
|
||||
))));
|
||||
)));
|
||||
let row = binaryMap
|
||||
.getBlackRow(binaryMap.getHeight() / 2)
|
||||
.expect("create");
|
||||
|
||||
@@ -72,7 +72,7 @@ fn testDecodingRowByRow() {
|
||||
.getStartEndMut()[1] = 0;
|
||||
|
||||
let secondRowNumber = 2 * binaryMap.getHeight() / 3;
|
||||
let mut secondRow = binaryMap.getBlackRow(secondRowNumber).expect("get row");
|
||||
let mut secondRow = binaryMap.getBlackRow(secondRowNumber).expect("get row").into_owned();
|
||||
secondRow.reverse();
|
||||
|
||||
let totalPairs = rssExpandedReader
|
||||
|
||||
@@ -39,7 +39,7 @@ fn getBufferedImage(fileName: &str) -> DynamicImage {
|
||||
pub(crate) fn getBinaryBitmap(fileName: &str) -> BinaryBitmap {
|
||||
let bufferedImage = getBufferedImage(fileName);
|
||||
|
||||
BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(bufferedImage)),
|
||||
))))
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user