標(biāo)題: 條形碼測(cè)試cpp [打印本頁(yè)]

作者: 51heiheihei123    時(shí)間: 2018-4-1 19:53
標(biāo)題: 條形碼測(cè)試cpp
#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 << "請(qǐng)確認(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 << "查詢條碼失敗,請(qǐng)檢查圖片!" << 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;
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1