条码识别-zxing-cpp-编译,使用指南
zxing-zpp下载地址:https://github.com/zxing-cpp/zxing-cpp
stb下载地址:https://github.com/nothings/stb
一、编译
1.分别下载好 zxing-cpp 和 stb 的源码(编译zxing-cpp需要stb)
2.使用cmake编译
如果不设置stb就会编译报错,需要下载stb源码,不用编译stb,只需要设置stb源码包的位置就可以了
其他的就是正常编译,最后使用vs2022编译后,生成的是静态库,保存在:build / core / release / ZXing.lib



二、使用
参考 zxing-cpp 的README文档编写就可以了,非常好用
// zxing(如果前面加载了 windows.h 就需要设置 NOMINMAX,不然会报一些错误) #define NOMINMAX #include "zxing/ReadBarcode.h" void Visualizer::scan_mode_code_scan() { #if 1 m_mutex.lock(); QImage img = m_img_scan.copy(); m_mutex.unlock(); img = img.convertToFormat(QImage::Format_Grayscale8); // 灰度化 auto image = ZXing::ImageView(img.bits(), img.width(), img.height(), ZXing::ImageFormat::Lum); auto options = ZXing::ReaderOptions().setFormats(ZXing::BarcodeFormat::Any); auto barcodes = ZXing::ReadBarcodes(image, options); qDebug() << "num:" << barcodes.size(); for (const auto& b : barcodes) { qDebug() << QString::fromStdString(ZXing::ToString(b.format())) << " : " << QString::fromStdString(b.text()); QMessageBox::information(this, "code", QString::fromStdString(b.text())); } #else }


三、编译好的库(静态库)
包含头文件,x86,x64的静态库,我是使用的vs2022编译的,zxing-zpp:V2.3.0版本
蓝奏云:https://wwqx.lanzoul.com/iVrgT2tq8k1c



浙公网安备 33010602011771号