标题: 条形码测试cpp [打印本页]

作者: 51heiheihei123    时间: 2018-4-1 19:53
标题: 条形码测试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 << "请确认图片" << 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;
}






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1