partially working qrcode blackbox

This commit is contained in:
Henry Schimke
2022-10-10 15:03:58 -05:00
parent 79aafa200d
commit 8785a7d0e7
3 changed files with 57 additions and 25 deletions

View File

@@ -169,7 +169,7 @@ fn decode_bitmatrix_parser_with_hints(
// for (DataBlock dataBlock : dataBlocks) { // for (DataBlock dataBlock : dataBlocks) {
let mut codewordBytes = dataBlock.getCodewords().to_vec(); let mut codewordBytes = dataBlock.getCodewords().to_vec();
let numDataCodewords = dataBlock.getNumDataCodewords() as usize; let numDataCodewords = dataBlock.getNumDataCodewords() as usize;
correctErrors(&mut codewordBytes, numDataCodewords); correctErrors(&mut codewordBytes, numDataCodewords)?;
for i in 0..numDataCodewords { for i in 0..numDataCodewords {
// for (int i = 0; i < numDataCodewords; i++) { // for (int i = 0; i < numDataCodewords; i++) {
resultBytes[resultOffset] = codewordBytes[i]; resultBytes[resultOffset] = codewordBytes[i];

View File

@@ -37,3 +37,6 @@ fn QRCodeBlackBox1TestCase() {
tester.testBlackBox(); tester.testBlackBox();
} }
// TEST CASE 15 FAILING AT allignment patter finder! (line 88) FROM detector 486

View File

@@ -17,7 +17,8 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs::{read_dir, read_to_string, File}, fs::{read_dir, read_to_string, File},
path::{Path, PathBuf}, io::Write, io::Write,
path::{Path, PathBuf},
}; };
use rxing::{ use rxing::{
@@ -114,7 +115,7 @@ impl AbstractBlackBoxTestCase {
let path_search = read_dir(&self.test_base); let path_search = read_dir(&self.test_base);
const possible_extensions: &str = "jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG"; const possible_extensions: &str = "jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG";
let paths = path_search let mut paths = path_search
.unwrap() .unwrap()
.into_iter() .into_iter()
.filter(|r| r.is_ok()) // Get rid of Err variants for Result<DirEntry> .filter(|r| r.is_ok()) // Get rid of Err variants for Result<DirEntry>
@@ -122,7 +123,9 @@ impl AbstractBlackBoxTestCase {
.filter(|r| r.is_file()) // Filter out non-folders .filter(|r| r.is_file()) // Filter out non-folders
.filter(|r| possible_extensions.contains(r.extension().unwrap().to_str().unwrap())) .filter(|r| possible_extensions.contains(r.extension().unwrap().to_str().unwrap()))
// .map(|r| r.into_boxed_path()) // .map(|r| r.into_boxed_path())
.collect(); .collect::<Vec<PathBuf>>();
paths.sort();
paths paths
} }
@@ -231,15 +234,16 @@ impl AbstractBlackBoxTestCase {
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 bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source)))); let bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source))));
// if file_base_name == "09" { #[cfg(test)]
// let mut f = File::create("test_file_output.txt").unwrap(); if file_base_name == "13" {
// dbg!("dumb"); let mut f = File::create("test_file_output.txt").unwrap();
// write!(f,"{}", bitmap.getBlackMatrix().unwrap()); dbg!("dumb");
// drop(f); write!(f,"{}", bitmap.getBlackMatrix().unwrap());
// Self::rotate_image(&image, rotation).save("test_image.png").unwrap(); drop(f);
// } Self::rotate_image(&image, rotation).save("test_image.png").unwrap();
}
if let Ok(decoded) = if let Ok(decoded) =
self.decode(&bitmap, rotation, &expected_text, &expected_metadata, false) self.decode(&bitmap, rotation, &expected_text, &expected_metadata, false)
{ {
@@ -497,23 +501,48 @@ impl AbstractBlackBoxTestCase {
// break; // break;
// } // }
let radians = degrees.to_radians(); if degrees == 90.0 {
original.rotate90()
} else if degrees == 180.0 {
original.rotate180()
} else if degrees == 270.0 {
original.rotate270()
} else {
let radians = degrees.to_radians();
{ {
use image::DynamicImage; use image::DynamicImage;
use image::Luma; use image::Luma;
use imageproc::geometric_transformations::*; use imageproc::geometric_transformations::*;
let i = rotate_about_center( let i = rotate_about_center(
&original.to_luma8(), &original.to_luma8(),
radians, radians,
Interpolation::Nearest, Interpolation::Nearest,
Luma([u8::MAX/2; 1]), Luma([u8::MAX / 2; 1]),
); );
DynamicImage::from(i) DynamicImage::from(i)
}
} }
// let radians = degrees.to_radians();
// {
// use image::DynamicImage;
// use image::Luma;
// use imageproc::geometric_transformations::*;
// let i = rotate_about_center(
// &original.to_luma8(),
// radians,
// Interpolation::Nearest,
// Luma([u8::MAX / 2; 1]),
// );
// DynamicImage::from(i)
// }
// // Transform simply to find out the new bounding box (don't actually run the image through it) // // Transform simply to find out the new bounding box (don't actually run the image through it)
// AffineTransform at = new AffineTransform(); // AffineTransform at = new AffineTransform();
// at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0); // at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0);