mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
some progress in passing images
This commit is contained in:
@@ -263,7 +263,7 @@ pub fn CenterOfRings(
|
||||
// for (int i = 1; i < numOfRings; ++i) {
|
||||
let c = CenterOfRing(image, center.floor(), range, i as i32, false)?;
|
||||
|
||||
if !(c == Point::default()) {
|
||||
if (c == Point::default()) {
|
||||
if n == 1 {
|
||||
return None;
|
||||
} else {
|
||||
@@ -566,7 +566,7 @@ pub fn LocateConcentricPattern<const E2E: bool, const LEN: usize, const SUM: usi
|
||||
center: Point,
|
||||
range: i32,
|
||||
) -> Option<ConcentricPattern> {
|
||||
let mut cur = EdgeTracer::new(image, center, Point::default());
|
||||
let mut cur = EdgeTracer::new(image, center.floor(), Point::default());
|
||||
let mut minSpread = image.getWidth() as i32;
|
||||
let mut maxSpread = 0_i32;
|
||||
|
||||
|
||||
@@ -20,23 +20,23 @@ impl<'a> FastEdgeToEdgeCounter<'a> {
|
||||
let p = ((cur.p().y as isize * cur.img().width() as isize).abs() as i32 + cur.p().x as i32)
|
||||
as u32; // P IS SET WRONG IN REVERSE
|
||||
|
||||
let maxStepsX = if cur.d().x != 0.0 {
|
||||
let maxStepsX: i32 = if cur.d().x != 0.0 {
|
||||
if cur.d().x > 0.0 {
|
||||
cur.img().width() - 1 - cur.p().x as u32
|
||||
cur.img().width() as i32 - 1 - cur.p().x as i32
|
||||
} else {
|
||||
cur.p().x as u32
|
||||
cur.p().x as i32
|
||||
}
|
||||
} else {
|
||||
u32::MAX
|
||||
i32::MAX
|
||||
};
|
||||
let maxStepsY = if cur.d().y != 0.0 {
|
||||
let maxStepsY: i32 = if cur.d().y != 0.0 {
|
||||
if cur.d().y > 0.0 {
|
||||
cur.img().height() - 1 - cur.p().y as u32
|
||||
cur.img().height() as i32 - 1 - cur.p().y as i32
|
||||
} else {
|
||||
cur.p().y as u32
|
||||
cur.p().y as i32
|
||||
}
|
||||
} else {
|
||||
u32::MAX
|
||||
i32::MAX
|
||||
};
|
||||
let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY) as i32;
|
||||
|
||||
|
||||
@@ -351,6 +351,16 @@ impl<'a> std::ops::Index<i32> for PatternView<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<Vec<PatternType>> for &PatternView<'a> {
|
||||
fn into(self) -> Vec<PatternType> {
|
||||
let mut v = vec![PatternType::default(); self.count as usize];
|
||||
for i in 0..self.count {
|
||||
v[i] = self[i];
|
||||
}
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The BarAndSpace struct is a simple 2 element data structure to hold information about bar(s) and space(s).
|
||||
*
|
||||
@@ -473,13 +483,13 @@ pub fn IsPattern<const E2E: bool, const LEN: usize, const SUM: usize, const SPAR
|
||||
module_size_ref: f32,
|
||||
// e2e: Option<bool>,
|
||||
) -> f32 {
|
||||
let e2e = E2E; //e2e.unwrap_or(false);
|
||||
//let e2e = E2E; //e2e.unwrap_or(false);
|
||||
let mut module_size_ref = module_size_ref;
|
||||
|
||||
if (e2e) {
|
||||
if E2E {
|
||||
//using float_t = double;
|
||||
|
||||
let widths = BarAndSpaceSum::<LEN, PatternType, f64>(&view.data().0);
|
||||
let v_src: Vec<PatternType> = view.into();
|
||||
let widths = BarAndSpaceSum::<LEN, PatternType, f64>(&v_src);
|
||||
let sums = pattern.sums();
|
||||
let modSize: BarAndSpace<f64> = BarAndSpace {
|
||||
bar: widths[0] / sums[0] as f64,
|
||||
@@ -534,7 +544,7 @@ pub fn IsPattern<const E2E: bool, const LEN: usize, const SUM: usize, const SPAR
|
||||
module_size_ref = module_size;
|
||||
}
|
||||
|
||||
let threshold = module_size_ref * (0.5 + (e2e as u8) as f32 * 0.25) + 0.5;
|
||||
let threshold = module_size_ref * (0.5 + (E2E as u8) as f32 * 0.25) + 0.5;
|
||||
|
||||
// the offset of 0.5 is to make the code less sensitive to quantization errors for small (near 1) module sizes.
|
||||
// TODO: review once we have upsampling in the binarizer in place.
|
||||
@@ -586,7 +596,7 @@ pub fn FindLeftGuardBy<'a, const LEN: usize, Pred: Fn(&PatternView, Option<f32>)
|
||||
}
|
||||
|
||||
let mut window = view.subView(0, Some(LEN));
|
||||
if window.isAtFirstBar() && isGuard(&window, None) {
|
||||
if window.isAtFirstBar() && isGuard(&window, Some(f32::MAX)) {
|
||||
return Ok(window);
|
||||
}
|
||||
let end = Into::<usize>::into(view.end().ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?) - minSize;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::{
|
||||
common::{
|
||||
cpp_essentials::{CenterOfRing, DMRegressionLine, FindConcentricPatternCorners, Matrix},
|
||||
cpp_essentials::{
|
||||
CenterOfRing, DMRegressionLine, FindConcentricPatternCorners, FindLeftGuardBy, Matrix,
|
||||
},
|
||||
DefaultGridSampler, GridSampler, Result, SamplerControl,
|
||||
},
|
||||
dimension, point_g, point_i,
|
||||
@@ -35,18 +37,26 @@ pub struct FinderPatternSet {
|
||||
pub type FinderPatterns = Vec<ConcentricPattern>;
|
||||
pub type FinderPatternSets = Vec<FinderPatternSet>;
|
||||
|
||||
const PATTERN: FixedPattern<5, 7, false> = FixedPattern::new([1, 1, 3, 1, 1]);
|
||||
const LEN: usize = 5;
|
||||
const SUM: usize = 7;
|
||||
const PATTERN: FixedPattern<LEN, SUM, false> = FixedPattern::new([1, 1, 3, 1, 1]);
|
||||
const E2E: bool = true;
|
||||
|
||||
// pub fn FindPattern( view: &PatternView) -> PatternView
|
||||
// {
|
||||
// return FindLeftGuard<PATTERN.size()>(view, PATTERN.size(), [](const PatternView& view, int spaceInPixel) {
|
||||
// // perform a fast plausability test for 1:1:3:1:1 pattern
|
||||
// if (view[2] < 2 * std::max(view[0], view[4]) || view[2] < std::max(view[1], view[3]))
|
||||
// return 0.f;
|
||||
// return IsPattern<E2E>(view, PATTERN, spaceInPixel, 0.5);
|
||||
// });
|
||||
// }
|
||||
fn FindPattern<'a>(view: PatternView<'a>) -> Result<PatternView<'a>> {
|
||||
FindLeftGuardBy::<LEN, _>(
|
||||
view,
|
||||
LEN,
|
||||
|view: &PatternView, spaceInPixel: Option<f32>| {
|
||||
// perform a fast plausability test for 1:1:3:1:1 pattern
|
||||
if (view[2] < 2 as PatternType * std::cmp::max(view[0], view[4])
|
||||
|| view[2] < std::cmp::max(view[1], view[3]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IsPattern::<E2E, 5, 7, false>(view, &PATTERN, spaceInPixel, 0.5, 0.0) != 0.0
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Locate the finder patterns for the symbol.
|
||||
/// This function can panic
|
||||
@@ -74,7 +84,7 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns
|
||||
let mut next: PatternView = PatternView::new(&row);
|
||||
|
||||
while {
|
||||
if let Ok(up_next) = FindLeftGuard(next, 0, &PATTERN, 0.5) {
|
||||
if let Ok(up_next) = FindPattern(next) {
|
||||
next = up_next;
|
||||
next.isValid()
|
||||
} else {
|
||||
@@ -105,7 +115,7 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns
|
||||
// Reduce(next) * 3); // 3 for very skewed samples
|
||||
if (pattern.is_some()) {
|
||||
// log(*pattern, 3);
|
||||
assert!(image.get_point(pattern.as_ref().unwrap().p));
|
||||
// assert!(image.get_point(pattern.as_ref().unwrap().p));
|
||||
res.push(pattern.unwrap());
|
||||
}
|
||||
}
|
||||
@@ -432,7 +442,8 @@ pub fn LocateAlignmentPattern(
|
||||
}
|
||||
|
||||
if let Some(cor1) = CenterOfRing(image, cor.unwrap(), moduleSize, 1, true) {
|
||||
if let Some(cor2) = CenterOfRing(image, cor.unwrap(), moduleSize * 3, -2, true) {
|
||||
if let Some(cor2) = CenterOfRing(image, cor.unwrap().floor(), moduleSize * 3, -2, true)
|
||||
{
|
||||
if Point::distance(cor1, cor2) < moduleSize as f32 / 2.0 {
|
||||
let res = (cor1 + cor2) / 2.0;
|
||||
// log(res, 3);
|
||||
|
||||
@@ -209,6 +209,7 @@ fn cpp_qrcode_black_box3_test_case() {
|
||||
QrReader::default(),
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
|
||||
tester.add_test(28, 28, 0.0);
|
||||
tester.add_test(28, 28, 90.0);
|
||||
tester.add_test(28, 28, 180.0);
|
||||
|
||||
Reference in New Issue
Block a user