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、在项目中打开属性

 

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

 

 

 

c、加入依赖项目

  1. 测试
#include <iostream>

#include <opencv2/highgui.hpp>

#include <opencv2/imgproc.hpp>

#include <opencv2/opencv.hpp>

#include "cvmethod.h"

#include <zbar.h>

#include <iomanip>

#include <vector>

#include <string>

#include <sstream>

//二维码转灰度图

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=" <<n << endl;

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

symbol != imageZbar.symbol_end();

++symbol) {

// do something useful with results

data = symbol->get_data();

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

}

}

else

{

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

}

imageZbar.set_data(NULL, 0);



string tmp;

vector<string> 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、测试结果

 

 

展开阅读全文
©️2020 CSDN 皮肤主题: 创作都市 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值