找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1693|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

條形碼測試cpp

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:300498 發(fā)表于 2018-4-1 19:53 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include "core/core.hpp"      
#include "highgui/highgui.hpp"      
#include "imgproc/imgproc.hpp"  
#include "video/tracking.hpp"  
#include<iostream>  

#include <iostream>
#include <zbar.h>
#define STR(s) #s

using namespace zbar;
using namespace cv;
using namespace std;

int main(int argc, char*argv[])
{
    ImageScanner scanner;
    scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    Mat image = imread("../data/2code.jpg");
    if (!image.data)
    {
        cout << "請確認(rèn)圖片" << 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();
    imageZbar.set_data(NULL, 0);
    return 0;
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表