simultaneous recognition UPC/EAN and UPC_EAN_EXTENCION

This commit is contained in:
Elnur Ismailzada 2019-05-17 00:43:11 +02:00
parent 82d4407c78
commit c35ca6492e
3 changed files with 31 additions and 0 deletions

View File

@ -422,6 +422,18 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
lastDecodeOperationSucceded_ = true;
} catch(zxing::Exception &/*e*/) {}
if (!lastDecodeOperationSucceded_ &&
hints.containsFormat(BarcodeFormat::UPC_EAN_EXTENSION) &&
!(hints & DecodeHints::PRODUCT_HINT).isEmpty() ) {
hints.setAllowedEanExtensions(std::set<int>());
try {
res = decoder->decode(bb, hints);
processingTime = t.elapsed();
lastDecodeOperationSucceded_ = true;
} catch(zxing::Exception &/*e*/) {}
}
if (tryHarder_ && bb->isRotateSupported()) {
Ref<BinaryBitmap> bbTmp = bb;

View File

@ -189,3 +189,20 @@ zxing::DecodeHints zxing::operator | (DecodeHints const& l, DecodeHints const& r
return result;
}
zxing::DecodeHints zxing::operator & (DecodeHints const& l, DecodeHints const& r) {
DecodeHints result (l);
result.hints &= r.hints;
if (!result.callback) {
result.callback = r.callback;
}
std::set<int> intersect;
std::set_intersection(l.allowedEanExtensions.begin(), l.allowedEanExtensions.end(),
r.allowedEanExtensions.begin(), r.allowedEanExtensions.end(),
std::inserter(intersect, intersect.begin()));
result.allowedEanExtensions = intersect;
return result;
}

View File

@ -30,6 +30,7 @@ namespace zxing {
typedef unsigned int DecodeHintType;
class DecodeHints;
DecodeHints operator | (DecodeHints const&, DecodeHints const&);
DecodeHints operator & (DecodeHints const&, DecodeHints const&);
class DecodeHints {
private:
@ -87,6 +88,7 @@ class DecodeHints {
DecodeHints& operator =(DecodeHints const &other);
friend DecodeHints operator| (DecodeHints const&, DecodeHints const&);
friend DecodeHints operator& (DecodeHints const&, DecodeHints const&);
};
}