Changeset View
Changeset View
Standalone View
Standalone View
src/barcodedecoder.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Line(s) | 157 | #ifdef HAVE_ZXING | |||
---|---|---|---|---|---|
168 | } catch (const std::exception &e) { | 168 | } catch (const std::exception &e) { | ||
169 | //qCDebug(Log) << e.what(); | 169 | //qCDebug(Log) << e.what(); | ||
170 | } | 170 | } | ||
171 | #else | 171 | #else | ||
172 | Q_UNUSED(img); | 172 | Q_UNUSED(img); | ||
173 | #endif | 173 | #endif | ||
174 | return {}; | 174 | return {}; | ||
175 | } | 175 | } | ||
176 | | ||||
177 | QString BarcodeDecoder::decodeQRCode(const QImage &img) | ||||
178 | { | ||||
179 | #ifdef HAVE_ZXING | ||||
180 | try { | ||||
181 | const zxing::Ref<zxing::LuminanceSource> source(new QImageLuminanceSource(img)); | ||||
182 | | ||||
183 | const zxing::Ref<zxing::Binarizer> binarizer(new zxing::HybridBinarizer(source)); | ||||
184 | const zxing::Ref<zxing::BinaryBitmap> binary(new zxing::BinaryBitmap(binarizer)); | ||||
185 | const zxing::DecodeHints hints(zxing::DecodeHints::QR_CODE_HINT); | ||||
186 | | ||||
187 | zxing::MultiFormatReader reader; | ||||
188 | const auto result = reader.decode(binary, hints); | ||||
189 | return QString::fromStdString(result->getText()->getText()); | ||||
190 | } catch (const std::exception &e) { | ||||
191 | //qCDebug(Log) << e.what(); | ||||
192 | } | ||||
193 | #else | ||||
194 | Q_UNUSED(img); | ||||
195 | #endif | ||||
196 | return {}; | ||||
197 | } |