port bitmatrix_curosor readpattern

This commit is contained in:
Henry Schimke
2023-03-21 11:22:31 -05:00
parent 94ad7753c2
commit 8486cba277
2 changed files with 27 additions and 18 deletions

View File

@@ -165,19 +165,26 @@ pub trait BitMatrixCursorTrait {
fn d(&self) -> Point; fn d(&self) -> Point;
fn readPattern<T>(&self, range: Option<u32>) -> Option<T> { fn readPattern<const LEN: usize, T: TryFrom<i32> + Default + Copy + Clone>(
// let range = range.unwrap_or(0); &mut self,
// let mut res :T; range: Option<i32>,
// for i in res.into_iter() { ) -> Option<[T; LEN]> {
// i = self.stepToEdge(1, range); let range = range.unwrap_or(0);
// } let mut res = [T::default(); LEN];
// // for (auto& i : res) for i in res.iter_mut() {
// // i = stepToEdge(1, range); *i = self
// return res; .stepToEdge(Some(1), Some(range), None)
todo!() .try_into()
.ok()?;
}
Some(res)
} }
fn readPatternFromBlack<T>(&mut self, maxWhitePrefix: i32, range: Option<u32>) -> Option<T> { fn readPatternFromBlack<const LEN: usize, T: TryFrom<i32> + Default + Copy + Clone>(
&mut self,
maxWhitePrefix: i32,
range: Option<i32>,
) -> Option<[T; LEN]> {
let range = range.unwrap_or(0); let range = range.unwrap_or(0);
if (maxWhitePrefix != 0 if (maxWhitePrefix != 0
&& self.isWhite() && self.isWhite()
@@ -186,6 +193,6 @@ pub trait BitMatrixCursorTrait {
return None; return None;
} }
// return readPattern<ARRAY>(range); // return readPattern<ARRAY>(range);
self.readPattern(Some(range)) self.readPattern::<LEN, _>(Some(range))
} }
} }

View File

@@ -751,7 +751,7 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
* case. * case.
*/ */
pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> { pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
type Pattern = Vec<PatternType>; type Pattern = [PatternType; 5];
// #ifdef PRINT_DEBUG // #ifdef PRINT_DEBUG
// SaveAsPBM(image, "weg.pbm"); // SaveAsPBM(image, "weg.pbm");
@@ -771,7 +771,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let tl = point_i(left, top); let tl = point_i(left, top);
let tr = point_i(right, top); let tr = point_i(right, top);
let bl = point_i(left, bottom); let bl = point_i(left, bottom);
let mut diagonal: Pattern = Vec::default(); let mut diagonal: Pattern = Default::default();
// allow corners be moved one pixel inside to accommodate for possible aliasing artifacts // allow corners be moved one pixel inside to accommodate for possible aliasing artifacts
for [p, d] in [ for [p, d] in [
[tl, point_i(1, 1)], [tl, point_i(1, 1)],
@@ -780,10 +780,10 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
] { ] {
// for (auto [p, d] : {std::pair(tl, PointI{1, 1}), {tr, {-1, 1}}, {bl, {1, -1}}}) { // for (auto [p, d] : {std::pair(tl, PointI{1, 1}), {tr, {-1, 1}}, {bl, {1, -1}}}) {
diagonal = EdgeTracer::new(image, p, d) diagonal = EdgeTracer::new(image, p, d)
.readPatternFromBlack(1, Some(width / 3 + 1)) .readPatternFromBlack(1, Some((width / 3 + 1) as i32))
.ok_or(Exceptions::NOT_FOUND)?; .ok_or(Exceptions::NOT_FOUND)?;
// diagonal = BitMatrixCursorI(image, p, d).readPatternFromBlack<Pattern>(1, width / 3 + 1); // diagonal = BitMatrixCursorI(image, p, d).readPatternFromBlack<Pattern>(1, width / 3 + 1);
let diag_hld = diagonal.clone().into(); let diag_hld = diagonal.to_vec().into();
let view = PatternView::new(&diag_hld); let view = PatternView::new(&diag_hld);
if (!(IsPattern(&view, &PATTERN, None, 0.0, 0.0, None) != 0.0)) { if (!(IsPattern(&view, &PATTERN, None, 0.0, 0.0, None) != 0.0)) {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
@@ -860,10 +860,12 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let bottom = top + height - 1; let bottom = top + height - 1;
// allow corners be moved one pixel inside to accommodate for possible aliasing artifacts // allow corners be moved one pixel inside to accommodate for possible aliasing artifacts
let diagonal = EdgeTracer::new(&image, point_i(left, top), point_i(1, 1)) let diagonal: Pattern = EdgeTracer::new(&image, point_i(left, top), point_i(1, 1))
.readPatternFromBlack(1, None) .readPatternFromBlack(1, None)
.ok_or(Exceptions::ILLEGAL_STATE)?; .ok_or(Exceptions::ILLEGAL_STATE)?;
if (!(IsPattern(diagonal, &PATTERN, None, 0.0, 0.0, None) != 0.0)) { let diag_hld = diagonal.to_vec().into();
let view = PatternView::new(&diag_hld);
if (!(IsPattern(&view, &PATTERN, None, 0.0, 0.0, None) != 0.0)) {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }