-
Notifications
You must be signed in to change notification settings - Fork 1
/
qrdecoder.cpp
41 lines (34 loc) · 1.38 KB
/
qrdecoder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "qrdecoder.h"
#include "zxingimagesource.h"
#include "zxing/core/src/zxing/ZXing.h"
#include "zxing/core/src/zxing/BinaryBitmap.h"
#include "zxing/core/src/zxing/Result.h"
#include "zxing/core/src/zxing/common/HybridBinarizer.h"
#include "zxing/core/src/zxing/DecodeHints.h"
#include "zxing/core/src/zxing/Reader.h"
#include "zxing/core/src/zxing/MultiFormatReader.h"
#include <QDebug>
#include <QtConcurrent/QtConcurrent>
QByteArray QRDecoder::decodeImage(QImage &image)
{
std::vector<zxing::Ref<zxing::Result> > results;
zxing::Ref<zxing::LuminanceSource> source(new ZXingImageSource(image));
try {
zxing::Ref<zxing::HybridBinarizer> binarizer(new zxing::HybridBinarizer(source));
zxing::DecodeHints hints(zxing::DecodeHints::DEFAULT_HINT);
hints.setTryHarder(false);
zxing::Ref<zxing::BinaryBitmap> binary(new zxing::BinaryBitmap(binarizer));
zxing::Ref<zxing::Reader> reader(new zxing::MultiFormatReader);
results.push_back(reader->decode(binary, hints));
} catch (...){
}
if (results.size() == 1) {
qDebug() << QString::fromStdString(results[0]->getText()->getText());
return QByteArray::fromStdString(results[0]->getText()->getText());
}
return QByteArray();
}
QFuture<QByteArray> QRDecoder::decodeImageAsync(QImage &image)
{
return QtConcurrent::run(&QRDecoder::decodeImage, image);
}