switch grey convert method

This commit is contained in:
Henry Schimke
2022-10-12 10:41:49 -05:00
parent 990a3f6727
commit 3602f9c2e8
6 changed files with 165 additions and 13 deletions

View File

@@ -21,7 +21,7 @@
// import java.awt.image.BufferedImage;
// import java.awt.image.WritableRaster;
use image::{DynamicImage, Luma, GenericImage, EncodableLayout};
use image::{DynamicImage, EncodableLayout, GenericImage, GrayImage, ImageBuffer, Luma};
use imageproc::geometric_transformations::rotate_about_center;
use crate::LuminanceSource;
@@ -98,13 +98,73 @@ impl BufferedImageLuminanceSource {
// }
let img = image.to_rgba8();
let mut raster: ImageBuffer<_, Vec<_>> = ImageBuffer::new(image.width(), image.height());
for x in 0..image.width() {
for y in 0..image.height() {
let pixel = img.get_pixel(x, y);
let [red, green, blue, alpha] = pixel.0;
if (alpha & 0xFF) == 0 {
// white, so we know its luminance is 255
raster.put_pixel(x, y, Luma([0xFF]))
// buffer[x] = 0xFF;
} else {
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
// 0x200 >> 10 is 0.5, it implements rounding.
raster.put_pixel(
x,
y,
Luma([((306 * (red as u32)
+ 601 * (green as u32)
+ 117 * (blue as u32)
+ 0x200)
>> 10) as u8]),
);
}
}
}
// for pixel in img.pixels() {
// // The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
// // black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
// // barcode image. Force any such pixel to be white:
// let [red,green,blue,alpha] = pixel.0;
// if (alpha & 0xFF) == 0 {
// // white, so we know its luminance is 255
// raster.push(0xFF);
// // buffer[x] = 0xFF;
// } else {
// // .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// // (306*R) >> 10 is approximately equal to R*0.299, and so on.
// // 0x200 >> 10 is 0.5, it implements rounding.
// raster.push((
// (306 * ((red as u32 >> 16) & 0xFF) +
// 601 * ((green as u32 >> 8) & 0xFF) +
// 117 * (blue as u32 & 0xFF) +
// 0x200) >> 10) as u8);
// }
// }
// let ib:ImageBuffer<Luma<u8>, Vec<u8>> = ImageBuffer::from_raw(image.width() , image.height(), raster).unwrap();
Self {
image: DynamicImage::from(image.to_luma8()),
image: DynamicImage::from(raster),
width: width,
height: height,
left: left,
top: top,
}
// Self {
// image: DynamicImage::from(image.to_luma8()),
// width: width,
// height: height,
// left: left,
// top: top,
// }
}
}
@@ -190,7 +250,7 @@ impl LuminanceSource for BufferedImageLuminanceSource {
&self.image.to_luma8(),
MINUS_45_IN_RADIANS,
imageproc::geometric_transformations::Interpolation::Nearest,
Luma([u8::MAX/2; 1]),
Luma([u8::MAX / 2; 1]),
);
let new_img = DynamicImage::from(img);

View File

@@ -4127,4 +4127,4 @@ impl HybridBinarizer {
}
blackPoints
}
}
}

View File

@@ -16,7 +16,7 @@ fn test_uri() {
#[test]
fn test_unicode() {
test_encode_decode("💸🎲🪜");
test_encode_decode("\u{11D4}\u{1185}\u{11c2}");
}
fn test_encode_decode(value: &str) {

View File

@@ -288,7 +288,7 @@ impl AlignmentPatternFinder {
) -> Option<AlignmentPattern> {
let stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
let centerJ = Self::centerFromEnd(stateCount, j);
let centerI = self.crossCheckVertical(
let centerI = self.crossCheckVertical(
i,
centerJ.floor() as u32,
2 * stateCount[1],

View File

@@ -38,6 +38,9 @@ fn QRCodeBlackBox1TestCase() {
tester.testBlackBox();
}
// 15 - 180 should pass
// 19 - 180 should pass
// 20 - 90 should pass
// TEST CASE 15 FAILING AT allignment patter finder! (line 88) FROM detector 486
@@ -124,4 +127,95 @@ Atul Starting src/test/resources/blackbox/qrcode-1/2.png
*/
/*
rxing TEST RESULTS::::
INFO :: Starting test_resources/blackbox/qrcode-1/1.png
INFO :: Starting test_resources/blackbox/qrcode-1/10.png
INFO :: Starting test_resources/blackbox/qrcode-1/11.png
INFO :: Starting test_resources/blackbox/qrcode-1/12.png
INFO :: Starting test_resources/blackbox/qrcode-1/13.png
FINE :: could not read at rotation 0
FINE :: could not read at rotation 0 w/TH
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
FINE :: could not read at rotation 180
FINE :: could not read at rotation 180 w/TH
FINE :: could not read at rotation 270
FINE :: could not read at rotation 270 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/14.png
FINE :: could not read at rotation 0
FINE :: could not read at rotation 0 w/TH
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
FINE :: could not read at rotation 180
FINE :: could not read at rotation 180 w/TH
FINE :: could not read at rotation 270
FINE :: could not read at rotation 270 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/15.png
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
FINE :: could not read at rotation 180
FINE :: could not read at rotation 180 w/TH
FINE :: could not read at rotation 270
FINE :: could not read at rotation 270 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/16.png
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
FINE :: could not read at rotation 270
FINE :: could not read at rotation 270 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/17.png
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/18.png
FINE :: could not read at rotation 0
FINE :: could not read at rotation 0 w/TH
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
FINE :: could not read at rotation 180
FINE :: could not read at rotation 180 w/TH
FINE :: could not read at rotation 270
FINE :: could not read at rotation 270 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/19.png
FINE :: could not read at rotation 180
FINE :: could not read at rotation 180 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/2.png
INFO :: Starting test_resources/blackbox/qrcode-1/20.png
FINE :: could not read at rotation 90
FINE :: could not read at rotation 90 w/TH
FINE :: could not read at rotation 270
FINE :: could not read at rotation 270 w/TH
INFO :: Starting test_resources/blackbox/qrcode-1/3.png
INFO :: Starting test_resources/blackbox/qrcode-1/4.png
INFO :: Starting test_resources/blackbox/qrcode-1/5.png
INFO :: Starting test_resources/blackbox/qrcode-1/6.png
INFO :: Starting test_resources/blackbox/qrcode-1/7.png
INFO :: Starting test_resources/blackbox/qrcode-1/8.png
INFO :: Starting test_resources/blackbox/qrcode-1/9.png
INFO :: Rotation 0 degrees:
INFO :: 17 of 20 images passed (17 required)
INFO :: 0 failed due to misreads, 3 not detected
INFO :: 17 of 20 images passed with try harder (17 required)
INFO :: 0 failed due to misreads, 3 not detected
INFO :: Rotation 90 degrees:
INFO :: 13 of 20 images passed (14 required)
INFO :: 0 failed due to misreads, 7 not detected
INFO :: 13 of 20 images passed with try harder (14 required)
INFO :: 0 failed due to misreads, 7 not detected
INFO :: Rotation 180 degrees:
INFO :: 15 of 20 images passed (17 required)
INFO :: 0 failed due to misreads, 5 not detected
INFO :: 15 of 20 images passed with try harder (17 required)
INFO :: 0 failed due to misreads, 5 not detected
INFO :: Rotation 270 degrees:
INFO :: 14 of 20 images passed (14 required)
INFO :: 0 failed due to misreads, 6 not detected
INFO :: 14 of 20 images passed with try harder (14 required)
INFO :: 0 failed due to misreads, 6 not detected
INFO :: Decoded 118 images out of 160 (73, 124 required)
WARN :: --- Test failed by 6 images
*/

View File

@@ -235,13 +235,11 @@ impl AbstractBlackBoxTestCase {
let source = BufferedImageLuminanceSource::new(rotated_image);
let bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source))));
// #[cfg(test)]
// if file_base_name == "14" {
// let mut f = File::create("test_file_output.txt").unwrap();
// dbg!("dumb");
// write!(f,"{}", bitmap.getBlackMatrix().unwrap());
// drop(f);
// Self::rotate_image(&image, rotation).save("test_image.png").unwrap();
// if file_base_name == "15" {
// let mut f = File::create("test_file_output.txt").unwrap();
// write!(f,"{}", bitmap.getBlackMatrix().unwrap());
// drop(f);
// Self::rotate_image(&image, rotation).save("test_image.png").unwrap();
// }
if let Ok(decoded) =