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