0
点赞
收藏
分享

微信扫一扫

[zbar]zbar条码扫描器解析示例

郝春妮 2022-06-13 阅读 63

 

//
// Created by leoxae on 2020/3/30.
//

#include "BarCodeRecogntion.h"

string BarCode::BarCodeRecognition(Mat image) {
string result;
zbar::ImageScanner scanner;
scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);

Mat imageGray;
cvtColor(image, imageGray, COLOR_RGB2GRAY);
int width = imageGray.cols;
int height = imageGray.rows;
auto *raw = (uchar *) imageGray.data;
zbar::Image imageZbar(width, height, "Y800", raw, width * height);
//扫描条码
scanner.scan(imageZbar);
zbar::Image::SymbolIterator symbol = imageZbar.symbol_begin();
if (imageZbar.symbol_begin() == imageZbar.symbol_end()) {
cout << "查询条码失败,请检查图片!" << endl;
}
for (; symbol != imageZbar.symbol_end(); ++symbol) {
cout << "类型:" << symbol->get_type_name() << endl;
cout << "条码:" << symbol->get_data() << endl;
result = symbol->get_data();
}
imshow("Source Image", image);
waitKey();
imageZbar.set_data(NULL, 0);

return result;
}

 

Talk is cheap. Show me the code

举报

相关推荐

0 条评论