包含目录
库目录
附加依赖项
文件在lib下
编译出现无法解析的外部符号:
换用64位版本的的Zbar
#include<Windows.h>
#include <iostream>
#include<zbar.h>
#include<opencv.hpp>
#include<string.h>
#include<opencv2\imgproc\types_c.h>//解决CV_RGB2GRAY:无法解析的标识符
using namespace cv;
using namespace zbar;
using namespace std;//string和cout
int main()
{
ImageScanner scanner;//定义扫描器
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
//加载图像
Mat image = imread("test_x40.bmp");
//图像转换
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();
//扫描结果打印
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();
imageZbar.set_data(NULL, 0);//清除缓存
return 0;
}
运行:
比OpenCV:
除了二维码还能识别条形码,据说识别速度也比OpenCV快