没有合适的资源?快使用搜索试试~ 我知道了~
首页zbar+OpenCV识别二维码、条形码内容,解决中文乱码
资源详情
资源评论
资源推荐

ZBar 是一个开源软件套件,用于从各种来源读取条形码,例如视频流,图像文件和原始强
度传感器。 它支持许多流行的符号(条形码类型),包括 EAN-13 / UPC-A,UPC-E,EAN-
8,Code 128,Code 39,Interleaved 2 of 5 和 QR Code。
注意:检测时应让码图占整个图的百分之八十以上,否则准确率感人!!!
#include "zbar.h"
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace std;
using namespace zbar; //添加 zbar 名称空间
using namespace cv;
int main(int argc, char*argv[])
{
ImageScanner scanner;
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
Mat image = imread("jj.jpg");
if (!image.data)
{
cout << "请确认图片" << endl;
system("pause");
return 0;
}
Mat imageGray;
cvtColor(image, imageGray, CV_RGB2GRAY);
int width = imageGray.cols;
int height = imageGray.rows;
uchar *raw = (uchar *)imageGray.data;
Image imageZbar(width, height, "Y800", raw, width * height);
scanner.scan(imageZbar); //扫描条码
Image::SymbolIterator symbol = imageZbar.symbol_begin();
if (imageZbar.symbol_begin() == imageZbar.symbol_end())
{
cout << "查询条码失败,请检查图片!" << endl;
}
for (; symbol != imageZbar.symbol_end(); ++symbol)
{
cout << "类型:" << endl << symbol->get_type_name() << endl <<
endl;
cout << "条码:" << endl << symbol->get_data() << endl << endl;
}
imshow("Source Image", image);
waitKey();















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0