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、測試結果

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章