Commit 11844b5c authored by Volker Krause's avatar Volker Krause
Browse files

Also detect 1D barcodes by default

parent 4f77b020
Pipeline #206832 passed with stage
in 8 minutes and 58 seconds
......@@ -40,7 +40,8 @@ enum {
static constexpr const auto SQUARE_MAX_ASPECT = 1.25f;
static constexpr const auto PDF417_MIN_ASPECT = 1.5f;
static constexpr const auto PDF417_MAX_ASPECT = 6.0f;
static constexpr const auto ANY1D_MIN_ASPECT = 6.0f;
static constexpr const auto ANY1D_MIN_ASPECT = 4.0f;
static constexpr const auto ANY1D_MAX_ASPECT = 8.0f;
BarcodeDecoder::BarcodeDecoder() = default;
BarcodeDecoder::~BarcodeDecoder() = default;
......@@ -118,7 +119,7 @@ BarcodeDecoder::BarcodeTypes BarcodeDecoder::isPlausibleAspectRatio(int width, i
}
// 1D
if (aspectRatio < ANY1D_MIN_ASPECT) {
if (aspectRatio < ANY1D_MIN_ASPECT || aspectRatio > ANY1D_MAX_ASPECT) {
hint &= ~Any1D;
}
......
......@@ -11,13 +11,17 @@ using namespace KItinerary;
enum {
// unit is 1/72 inch, assuming landscape orientation
MinTargetImageHeight = 28,
MinTargetImageHeight2D = 28,
MinTargetImageHeight1D = 20,
MinTargetImageWidth = 36,
MaxTargetImageHeight = 252,
MaxTargetImageWidth2D = 252,
MaxTargetImageWidth1D = 272,
// vector path complexity limits
MinPathElementCount2D = 400,
MaxPathElementCount2D = 4000,
MinPathElementCount1D = 200,
MaxPathElementCount1D = 400,
};
BarcodeDecoder::BarcodeTypes PdfBarcodeUtil::maybeBarcode(const PdfImage &img, BarcodeDecoder::BarcodeTypes hint)
......@@ -26,13 +30,16 @@ BarcodeDecoder::BarcodeTypes PdfBarcodeUtil::maybeBarcode(const PdfImage &img, B
const auto h = img.height();
// image target size checks
if (std::min(w, h) < MinTargetImageHeight || std::max(w, h) < MinTargetImageWidth || std::min(w, h) > MaxTargetImageHeight) {
if (std::max(w, h) < MinTargetImageWidth || std::min(w, h) > MaxTargetImageHeight) {
return BarcodeDecoder::None;
}
if (std::max(w, h) > MaxTargetImageWidth2D) {
if (std::max(w, h) > MaxTargetImageWidth2D || std::min(w, h) < MinTargetImageHeight2D) {
hint &= ~BarcodeDecoder::Any2D;
}
if (std::max(w, h) > MaxTargetImageWidth1D || std::min(w, h) < MinTargetImageHeight1D) {
hint &= ~BarcodeDecoder::Any1D;
}
hint = BarcodeDecoder::isPlausibleSize(img.sourceWidth(), img.sourceHeight(), hint);
hint = BarcodeDecoder::isPlausibleAspectRatio(w, h, hint);
......@@ -49,5 +56,8 @@ BarcodeDecoder::BarcodeTypes PdfBarcodeUtil::isPlausiblePath(int elementCount, B
if (elementCount < MinPathElementCount2D || elementCount > MaxPathElementCount2D) {
hint &= ~BarcodeDecoder::Any2D;
}
if (elementCount < MinPathElementCount1D || elementCount > MaxPathElementCount1D) {
hint &= ~BarcodeDecoder::Any1D;
}
return hint;
}
......@@ -36,7 +36,7 @@ void ImageDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extra
const auto img = node.content<QImage>();
BarcodeDecoder::BarcodeTypes barcodeHints = BarcodeDecoder::Any2D;
BarcodeDecoder::BarcodeTypes barcodeHints = BarcodeDecoder::Any2D | BarcodeDecoder::Any1D;
// check whether we possibly have a full PDF page raster image here
if (engine->hints() & ExtractorEngine::ExtractFullPageRasterImages) {
barcodeHints |= BarcodeDecoder::IgnoreAspectRatio;
......
......@@ -91,7 +91,7 @@ void PdfDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extract
continue;
}
const auto barcodeHints = PdfBarcodeUtil::maybeBarcode(img, BarcodeDecoder::Any2D);
const auto barcodeHints = PdfBarcodeUtil::maybeBarcode(img, BarcodeDecoder::Any2D | BarcodeDecoder::Any1D);
if (barcodeHints == BarcodeDecoder::None) {
continue;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment