add try-harder for pure barcode to datamatrix

This commit is contained in:
Henry Schimke
2023-01-15 16:53:59 -06:00
parent 36327480d8
commit c9eb6f88cf

View File

@@ -17,9 +17,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::{ use crate::{
common::{BitMatrix, DetectorRXingResult}, common::{BitMatrix, DecoderRXingResult, DetectorRXingResult},
BarcodeFormat, DecodeHintType, Exceptions, RXingResult, RXingResultMetadataType, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
RXingResultMetadataValue, Reader, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
use super::{decoder::Decoder, detector::Detector}; use super::{decoder::Decoder, detector::Detector};
@@ -69,6 +69,13 @@ impl Reader for DataMatrixReader {
image: &mut crate::BinaryBitmap, image: &mut crate::BinaryBitmap,
hints: &crate::DecodingHintDictionary, hints: &crate::DecodingHintDictionary,
) -> Result<crate::RXingResult, crate::Exceptions> { ) -> Result<crate::RXingResult, crate::Exceptions> {
let try_harder = if let Some(DecodeHintValue::TryHarder(true)) =
hints.get(&DecodeHintType::TRY_HARDER)
{
true
} else {
false
};
let decoderRXingResult; let decoderRXingResult;
let mut points = Vec::new(); let mut points = Vec::new();
if hints.contains_key(&DecodeHintType::PURE_BARCODE) { if hints.contains_key(&DecodeHintType::PURE_BARCODE) {
@@ -76,10 +83,24 @@ impl Reader for DataMatrixReader {
decoderRXingResult = DECODER.decode(&bits)?; decoderRXingResult = DECODER.decode(&bits)?;
points.clear(); points.clear();
} else { } else {
let detectorRXingResult = Detector::new(image.getBlackMatrix())?.detect()?; //Result<DatamatrixDetectorResult, Exceptions>
decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?; decoderRXingResult = if let Ok(fnd) = || -> Result<DecoderRXingResult, Exceptions> {
points = detectorRXingResult.getPoints().to_vec(); let detectorRXingResult = Detector::new(image.getBlackMatrix())?.detect()?;
let decoded = DECODER.decode(detectorRXingResult.getBits())?;
points = detectorRXingResult.getPoints().to_vec();
Ok(decoded)
}() {
fnd
} else if try_harder {
let bits = self.extractPureBits(image.getBlackMatrix())?;
DECODER.decode(&bits)?
} else {
return Err(Exceptions::NotFoundException(None));
};
// decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?;
} }
let mut result = RXingResult::new( let mut result = RXingResult::new(
decoderRXingResult.getText(), decoderRXingResult.getText(),
decoderRXingResult.getRawBytes().clone(), decoderRXingResult.getRawBytes().clone(),