mirror of
https://github.com/status-im/qzxing.git
synced 2025-02-18 22:06:57 +00:00
Introduced new option for QZXing. if QZXing::setTryHarder is set to true, if the image decoding fails, the image will be rotated and will be tested against angles 90o, 180o, 270o. This increased the success rate for the Qr codes.
Plus, minor changes at the handling of failed decoding in QZXing.
This commit is contained in:
parent
0ecf27cc37
commit
7f86f35883
@ -75,6 +75,8 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void setTryHarder(bool tryHarder);
|
||||||
|
bool getTryHarder();
|
||||||
static QString decoderFormatToString(int fmt);
|
static QString decoderFormatToString(int fmt);
|
||||||
QString foundedFormat() const;
|
QString foundedFormat() const;
|
||||||
QString charSet() const;
|
QString charSet() const;
|
||||||
@ -166,6 +168,7 @@ private:
|
|||||||
int processingTime;
|
int processingTime;
|
||||||
QString foundedFmt;
|
QString foundedFmt;
|
||||||
QString charSet_;
|
QString charSet_;
|
||||||
|
bool tryHarder_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, the decoding operation will take place at a different thread.
|
* If true, the decoding operation will take place at a different thread.
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
using namespace zxing;
|
using namespace zxing;
|
||||||
|
|
||||||
QZXing::QZXing(QObject *parent) : QObject(parent)
|
QZXing::QZXing(QObject *parent) : QObject(parent), tryHarder_(false)
|
||||||
{
|
{
|
||||||
decoder = new MultiFormatReader();
|
decoder = new MultiFormatReader();
|
||||||
/*setDecoder(DecoderFormat_QR_CODE |
|
/*setDecoder(DecoderFormat_QR_CODE |
|
||||||
@ -48,6 +48,16 @@ QZXing::QZXing(QZXing::DecoderFormat decodeHints, QObject *parent) : QObject(par
|
|||||||
setDecoder(decodeHints);
|
setDecoder(decodeHints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QZXing::setTryHarder(bool tryHarder)
|
||||||
|
{
|
||||||
|
tryHarder_ = tryHarder;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QZXing::getTryHarder()
|
||||||
|
{
|
||||||
|
return tryHarder_;
|
||||||
|
}
|
||||||
|
|
||||||
QString QZXing::decoderFormatToString(int fmt)
|
QString QZXing::decoderFormatToString(int fmt)
|
||||||
{
|
{
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
@ -196,6 +206,7 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
|
|||||||
else
|
else
|
||||||
ciw = CameraImageWrapper::Factory(image, 999, 999, true);
|
ciw = CameraImageWrapper::Factory(image, 999, 999, true);
|
||||||
|
|
||||||
|
QString errorMessage = "Unknown";
|
||||||
try {
|
try {
|
||||||
Ref<LuminanceSource> imageRef(ciw);
|
Ref<LuminanceSource> imageRef(ciw);
|
||||||
Ref<GlobalHistogramBinarizer> binz( new GlobalHistogramBinarizer(imageRef) );
|
Ref<GlobalHistogramBinarizer> binz( new GlobalHistogramBinarizer(imageRef) );
|
||||||
@ -214,11 +225,11 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
|
|||||||
hints.setTryHarder(true);
|
hints.setTryHarder(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res = decoder->decode(bb, hints);
|
res = decoder->decode(bb, hints);
|
||||||
hasSucceded = true;
|
hasSucceded = true;
|
||||||
} catch(zxing::Exception &e) {}
|
} catch(zxing::Exception &e) {}
|
||||||
|
|
||||||
if (bb->isRotateSupported()) {
|
if (tryHarder_ && bb->isRotateSupported()) {
|
||||||
Ref<BinaryBitmap> bbTmp = bb;
|
Ref<BinaryBitmap> bbTmp = bb;
|
||||||
|
|
||||||
for (int i=0; (i<3 && !hasSucceded); i++) {
|
for (int i=0; (i<3 && !hasSucceded); i++) {
|
||||||
@ -233,30 +244,34 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString string = QString(res->getText()->getText().c_str());
|
if (hasSucceded) {
|
||||||
if (!string.isEmpty() && (string.length() > 0)) {
|
QString string = QString(res->getText()->getText().c_str());
|
||||||
int fmt = res->getBarcodeFormat().value;
|
if (!string.isEmpty() && (string.length() > 0)) {
|
||||||
foundedFmt = decoderFormatToString(fmt);
|
int fmt = res->getBarcodeFormat().value;
|
||||||
charSet_ = QString::fromStdString(res->getCharSet());
|
foundedFmt = decoderFormatToString(fmt);
|
||||||
if (!charSet_.isEmpty()) {
|
charSet_ = QString::fromStdString(res->getCharSet());
|
||||||
QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str());
|
if (!charSet_.isEmpty()) {
|
||||||
if (codec)
|
QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str());
|
||||||
string = codec->toUnicode(res->getText()->getText().c_str());
|
if (codec)
|
||||||
|
string = codec->toUnicode(res->getText()->getText().c_str());
|
||||||
|
}
|
||||||
|
emit tagFound(string);
|
||||||
|
emit tagFoundAdvanced(string, foundedFmt, charSet_);
|
||||||
}
|
}
|
||||||
emit tagFound(string);
|
processingTime = t.elapsed();
|
||||||
emit tagFoundAdvanced(string, foundedFmt, charSet_);
|
emit decodingFinished(true);
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
processingTime = t.elapsed();
|
|
||||||
emit decodingFinished(true);
|
|
||||||
return string;
|
|
||||||
}
|
}
|
||||||
catch(zxing::Exception &e)
|
catch(zxing::Exception &e)
|
||||||
{
|
{
|
||||||
emit error(QString(e.what()));
|
errorMessage = QString(e.what());
|
||||||
emit decodingFinished(false);
|
|
||||||
processingTime = t.elapsed();
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit error(errorMessage);
|
||||||
|
emit decodingFinished(false);
|
||||||
|
processingTime = t.elapsed();
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QZXing::decodeImageFromFile(const QString& imageFilePath, int maxWidth, int maxHeight, bool smoothTransformation)
|
QString QZXing::decodeImageFromFile(const QString& imageFilePath, int maxWidth, int maxHeight, bool smoothTransformation)
|
||||||
@ -335,7 +350,7 @@ QImage QZXing::encodeData(const QString& data)
|
|||||||
qRgb(255,255,255));
|
qRgb(255,255,255));
|
||||||
|
|
||||||
image = image.scaled(240, 240);
|
image = image.scaled(240, 240);
|
||||||
// bool success = image.save("tmp.bmp","BMP");
|
// bool success = image.save("tmp.bmp","BMP");
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
std::cout << "Error: " << e.what() << std::endl;
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
DecodeValidator::DecodeValidator() : decoder(), decoderCorrelationMap(), testResults()
|
DecodeValidator::DecodeValidator() : decoder(), decoderCorrelationMap(), testResults()
|
||||||
{
|
{
|
||||||
initializeDecoderCorrelation();
|
initializeDecoderCorrelation();
|
||||||
|
decoder.setTryHarder(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodeValidator::initializeDecoderCorrelation()
|
void DecodeValidator::initializeDecoderCorrelation()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user