mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
cargo fmt
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//package com.google.zxing;
|
//package com.google.zxing;
|
||||||
|
|
||||||
use std::{rc::Rc, borrow::Cow};
|
use std::{borrow::Cow, rc::Rc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitArray, BitMatrix},
|
common::{BitArray, BitMatrix},
|
||||||
@@ -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(& 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
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//package com.google.zxing;
|
//package com.google.zxing;
|
||||||
|
|
||||||
use std::{fmt, rc::Rc, borrow::Cow};
|
use std::{borrow::Cow, fmt, rc::Rc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitArray, BitMatrix},
|
common::{BitArray, BitMatrix},
|
||||||
@@ -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(& self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
pub fn getBlackRow(&self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
||||||
self.binarizer.getBlackRow(y)
|
self.binarizer.getBlackRow(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,12 +88,7 @@ impl BinaryBitmap {
|
|||||||
// 1D Reader finds a barcode before the 2D Readers run.
|
// 1D Reader finds a barcode before the 2D Readers run.
|
||||||
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
|
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
|
||||||
if self.matrix.is_none() {
|
if self.matrix.is_none() {
|
||||||
self.matrix = Some(
|
self.matrix = Some(self.binarizer.getBlackMatrix().unwrap().clone());
|
||||||
self.binarizer
|
|
||||||
.getBlackMatrix()
|
|
||||||
.unwrap()
|
|
||||||
.clone(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
self.matrix.as_mut().unwrap()
|
self.matrix.as_mut().unwrap()
|
||||||
}
|
}
|
||||||
@@ -114,12 +109,7 @@ impl BinaryBitmap {
|
|||||||
// 1D Reader finds a barcode before the 2D Readers run.
|
// 1D Reader finds a barcode before the 2D Readers run.
|
||||||
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
|
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
|
||||||
if self.matrix.is_none() {
|
if self.matrix.is_none() {
|
||||||
self.matrix = Some(
|
self.matrix = Some(self.binarizer.getBlackMatrix().unwrap().clone())
|
||||||
self.binarizer
|
|
||||||
.getBlackMatrix()
|
|
||||||
.unwrap()
|
|
||||||
.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
self.matrix.as_ref().unwrap()
|
self.matrix.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
@@ -160,10 +150,7 @@ impl BinaryBitmap {
|
|||||||
* @return Whether this bitmap supports counter-clockwise rotation.
|
* @return Whether this bitmap supports counter-clockwise rotation.
|
||||||
*/
|
*/
|
||||||
pub fn isRotateSupported(&self) -> bool {
|
pub fn isRotateSupported(&self) -> bool {
|
||||||
return self
|
return self.binarizer.getLuminanceSource().isRotateSupported();
|
||||||
.binarizer
|
|
||||||
.getLuminanceSource()
|
|
||||||
.isRotateSupported();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,10 +160,7 @@ impl BinaryBitmap {
|
|||||||
* @return A rotated version of this object.
|
* @return A rotated version of this object.
|
||||||
*/
|
*/
|
||||||
pub fn rotateCounterClockwise(&mut self) -> BinaryBitmap {
|
pub fn rotateCounterClockwise(&mut self) -> BinaryBitmap {
|
||||||
let newSource = self
|
let newSource = self.binarizer.getLuminanceSource().rotateCounterClockwise();
|
||||||
.binarizer
|
|
||||||
.getLuminanceSource()
|
|
||||||
.rotateCounterClockwise();
|
|
||||||
return BinaryBitmap::new(
|
return BinaryBitmap::new(
|
||||||
self.binarizer
|
self.binarizer
|
||||||
.createBinarizer(newSource.expect("new lum source expected")),
|
.createBinarizer(newSource.expect("new lum source expected")),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
// import com.google.zxing.LuminanceSource;
|
// import com.google.zxing.LuminanceSource;
|
||||||
// import com.google.zxing.NotFoundException;
|
// import com.google.zxing.NotFoundException;
|
||||||
|
|
||||||
use std::{rc::Rc, borrow::Cow};
|
use std::{borrow::Cow, rc::Rc};
|
||||||
|
|
||||||
use once_cell::unsync::OnceCell;
|
use once_cell::unsync::OnceCell;
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@ 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(& self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
fn getBlackRow(&self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
||||||
let row = self.black_row_cache[y].get_or_try_init(||{
|
let row = self.black_row_cache[y].get_or_try_init(|| {
|
||||||
let source = self.getLuminanceSource();
|
let source = self.getLuminanceSource();
|
||||||
let width = source.getWidth();
|
let width = source.getWidth();
|
||||||
let mut row = BitArray::with_size(width);
|
let mut row = BitArray::with_size(width);
|
||||||
@@ -65,8 +65,8 @@ impl Binarizer for GlobalHistogramBinarizer {
|
|||||||
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)
|
||||||
[((localLuminances[x]) >> GlobalHistogramBinarizer::LUMINANCE_SHIFT) as usize] += 1;
|
as usize] += 1;
|
||||||
}
|
}
|
||||||
let blackPoint = Self::estimateBlackPoint(&localBuckets)?;
|
let blackPoint = Self::estimateBlackPoint(&localBuckets)?;
|
||||||
|
|
||||||
@@ -98,24 +98,22 @@ impl Binarizer for GlobalHistogramBinarizer {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Cow::Borrowed(row))
|
Ok(Cow::Borrowed(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(& 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))?;
|
let matrix = self
|
||||||
|
.black_matrix
|
||||||
|
.get_or_try_init(|| Self::build_black_matrix(&self.source))?;
|
||||||
Ok(matrix)
|
Ok(matrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createBinarizer(
|
fn createBinarizer(&self, source: Box<dyn crate::LuminanceSource>) -> Rc<dyn Binarizer> {
|
||||||
&self,
|
|
||||||
source: Box<dyn crate::LuminanceSource>,
|
|
||||||
) -> Rc<dyn Binarizer> {
|
|
||||||
Rc::new(GlobalHistogramBinarizer::new(source))
|
Rc::new(GlobalHistogramBinarizer::new(source))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
// import com.google.zxing.LuminanceSource;
|
// import com.google.zxing.LuminanceSource;
|
||||||
// import com.google.zxing.NotFoundException;
|
// import com.google.zxing.NotFoundException;
|
||||||
|
|
||||||
use std::{rc::Rc, borrow::Cow};
|
use std::{borrow::Cow, rc::Rc};
|
||||||
|
|
||||||
use once_cell::unsync::OnceCell;
|
use once_cell::unsync::OnceCell;
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ impl Binarizer for HybridBinarizer {
|
|||||||
self.ghb.getLuminanceSource()
|
self.ghb.getLuminanceSource()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getBlackRow(& self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
fn getBlackRow(&self, y: usize) -> Result<Cow<BitArray>, Exceptions> {
|
||||||
self.ghb.getBlackRow(y)
|
self.ghb.getBlackRow(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ 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(& 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)
|
||||||
@@ -74,7 +74,9 @@ impl Binarizer for HybridBinarizer {
|
|||||||
// )
|
// )
|
||||||
// }
|
// }
|
||||||
// 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))?;
|
let matrix = self
|
||||||
|
.black_matrix
|
||||||
|
.get_or_try_init(|| Self::calculateBlackMatrix(&self.ghb))?;
|
||||||
Ok(matrix)
|
Ok(matrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ impl HybridBinarizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculateBlackMatrix(ghb: & 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();
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ 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(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 +65,7 @@ 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(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,7 @@ 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(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");
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
* http://www.piramidepse.com/
|
* http://www.piramidepse.com/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{rc::Rc};
|
use std::rc::Rc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
@@ -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 binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
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 binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
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 binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
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");
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
* http://www.piramidepse.com/
|
* http://www.piramidepse.com/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{rc::Rc};
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::GlobalHistogramBinarizer,
|
common::GlobalHistogramBinarizer,
|
||||||
@@ -42,9 +42,9 @@ use super::RSSExpandedReader;
|
|||||||
#[test]
|
#[test]
|
||||||
fn testFindFinderPatterns() {
|
fn testFindFinderPatterns() {
|
||||||
let image = readImage("2.png");
|
let image = readImage("2.png");
|
||||||
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
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 binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
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 binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image.clone())),
|
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 binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(
|
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(image.clone())),
|
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,10 @@ 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").into_owned();
|
let mut secondRow = binaryMap
|
||||||
|
.getBlackRow(secondRowNumber)
|
||||||
|
.expect("get row")
|
||||||
|
.into_owned();
|
||||||
secondRow.reverse();
|
secondRow.reverse();
|
||||||
|
|
||||||
let totalPairs = rssExpandedReader
|
let totalPairs = rssExpandedReader
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
* http://www.piramidepse.com/
|
* http://www.piramidepse.com/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{rc::Rc};
|
use std::rc::Rc;
|
||||||
|
|
||||||
use image::DynamicImage;
|
use image::DynamicImage;
|
||||||
|
|
||||||
@@ -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(GlobalHistogramBinarizer::new(
|
BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(
|
||||||
Box::new(BufferedImageLuminanceSource::new(bufferedImage)),
|
BufferedImageLuminanceSource::new(bufferedImage),
|
||||||
)))
|
))))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,9 +237,7 @@ 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(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();
|
||||||
|
|||||||
@@ -178,9 +178,8 @@ 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(
|
let mut bitmap =
|
||||||
HybridBinarizer::new(Box::new(source)),
|
BinaryBitmap::new(Rc::new(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)
|
||||||
@@ -387,9 +386,7 @@ 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(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