找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1307|回复: 0
打印 上一主题 下一主题
收起左侧

条形码测试cpp

[复制链接]
跳转到指定楼层
楼主
ID:300498 发表于 2018-4-1 19:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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;
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表