c++ zbar+opencv+vs二维码识别配置及其实例

1、资源:

链接:https://pan.baidu.com/s/1FAxsQJ6eiBusU4AgJp9iLQ

提取码:vd1v

2、关于Zbar在VS+opencv教程

  1.   配置环境变量:将ZBar中bin配置到环境变量E:\app\ZBar\bin
  2. 在VS配置,本项目使用64位

a、在项目中打开属性

c++ zbar+opencv+vs二维码识别配置及其实例_第1张图片

 

b、把Zbar中的include和ilb文件夹路径分别加入

c++ zbar+opencv+vs二维码识别配置及其实例_第2张图片

 

c++ zbar+opencv+vs二维码识别配置及其实例_第3张图片

 

c++ zbar+opencv+vs二维码识别配置及其实例_第4张图片

 

c、加入依赖项目

c++ zbar+opencv+vs二维码识别配置及其实例_第5张图片

  1. 测试
#include 

#include 

#include 

#include 

#include "cvmethod.h"

#include 

#include 

#include 

#include 

#include 

//二维码转灰度图

cvtColor(qCodeImage,qCodeImage, CV_RGB2GRAY);

int qw, qh;

qw = qCodeImage.cols;

qh = qCodeImage.rows;

imshow("二维码",qCodeImage);

ImageScanner scanner;

scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);

uchar *pdate = (uchar *)qCodeImage.data;

zbar::Image imageZbar(qw, qh, "Y800", pdate, qw * qh);

Image::SymbolIterator symbol = imageZbar.symbol_begin();

int n = scanner.scan(imageZbar);

//n>0则表示有数据

if (n>0)

{

cout << "->二维码数据读取成功;n=" <get_data();

cout <<"->获取二维码数据:"<< data  << endl;

}

}

else

{

cout << "->查询二维码失败,请检查图片!" << endl;

}

imageZbar.set_data(NULL, 0);



string tmp;

vector qdata;

stringstream input(data);



while (getline(input, tmp, ',')) qdata.push_back(tmp);

Invoice invoice;

for (int i = 0; i < qdata.size(); i++) {

switch (i)

{

case 0:

break;

case 1:

break;

case 2:

invoice.code = qdata[i];

cout << "->数据分析:获取发票代码成功[:" << invoice.code <<"]"<< endl;

break;

case 3:

invoice.num = qdata[i];

cout << "->数据分析:获取发票号码成功[:" << invoice.num << "]" << endl;

break;

case 4:

invoice.goodsPrice = qdata[i];

cout << "->数据分析:获取发票商品价格成功[:" << invoice.goodsPrice << "]" << endl;

break;

case 5:

invoice.date = qdata[i];

cout << "->数据分析:获取发票日期成功[:" << invoice.date << "]" << endl;

break;

case 6:

invoice.checkCode = qdata[i];

cout << "->数据分析:获取发票校验码成功[:" << invoice.checkCode << "]" << endl;

break;

default:

break;

}

};

4、测试结果

 

c++ zbar+opencv+vs二维码识别配置及其实例_第6张图片

 

你可能感兴趣的:(c++,opencv)