zoukankan      html  css  js  c++  java
  • zbar配置

    1、下载安装zbar,选择full全部安装。也可以从这里下载

     2、由于官方给的是32位的,继续下载64位的zbar

    替换文件:

    • 将ZBarWin64-master\lib 文件夹下 libzbar64-0.lib 文件复制到ZBar安装路径下的 lib 文件夹;
    • 将 ZBarWin64-master\lib 文件夹下 libzbar64-0.dll 文件复制到ZBar安装路径下的 bin 文件夹;
    • 将ZBarWin64-master\zbar\libiconv\dll_x64文件夹下 libiconv.dll 复制到ZBar安装路径下的bin 文件夹;

    3、将bin目录添加到环境变量

    【实战】

    VS创建控制台应用

    #include <opencv.hpp>
    #include <zbar.h>
    
    #include <iostream>
    
    using namespace cv;
    using namespace zbar;
    using namespace std;
    
    int main()
    {
        //定义扫描器
        ImageScanner scanner;
        scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    
        //加载图片
        Mat image = imread("D:/qrcode.jpg");
        if (!image.data)
        {
            cout << "图片为空,请确认!" << endl;
            system("pause");
            return 0;
        }
    
        //图片转换,Mat转Image
        Mat imageGray;
        cvtColor(image, imageGray, COLOR_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;
            cout << "条码:" << endl << symbol->get_data() << endl;
        }
    
        //显示
        imshow("Source Image", image);
        waitKey();
        imageZbar.set_data(NULL, 0);//清除缓存
        return 0;
    
    
        std::cout << "Hello World!\n";
    }

     我的属性表.props如下:

    标黄部分修改为自己的版本,VS中添加属性表即可。

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ImportGroup Label="PropertySheets" />
      <PropertyGroup Label="UserMacros" />
      <PropertyGroup />
      <ItemDefinitionGroup>
        <ClCompile>
          <AdditionalIncludeDirectories>C:\opencv\debug\build\include;C:\opencv\debug\build\include\opencv2;C:\Program Files %28x86%29\ZBar\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
        </ClCompile>
        <Link>
          <AdditionalLibraryDirectories>C:\opencv\debug\build\lib;C:\Program Files %28x86%29\ZBar\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
          <AdditionalDependencies>opencv_calib3d455d.lib;opencv_core455d.lib;opencv_dnn455d.lib;opencv_features2d455d.lib;opencv_flann455d.lib;opencv_gapi455d.lib;opencv_highgui455d.lib;opencv_imgcodecs455d.lib;opencv_imgproc455d.lib;opencv_ml455d.lib;opencv_objdetect455d.lib;opencv_photo455d.lib;opencv_stitching455d.lib;opencv_video455d.lib;opencv_videoio455d.lib;libzbar64-0.lib;%(AdditionalDependencies)</AdditionalDependencies>
        </Link>
      </ItemDefinitionGroup>
      <ItemGroup />
    </Project>
  • 相关阅读:
    2018最新php笔试题及答案(持续更新)
    快速上手模板制作
    春节期间小游戏同时在线人数最高达2800万人/小时
    公众平台新增修改文章错别字功能 每篇文章允许被修改一次仅限正文内五个字
    微信6.6.2版更新:支持两个账号一键切换
    小程序支持打开APP了 还有小程序的标题栏也可以自定义
    小程序发布重磅数据:日活跃用户数1.7亿、已上线小程序58万个,覆盖100万开发者、2300个第三方平台
    张小龙2018PRO版微信公开课演讲全文 透露2018微信全新计划
    除了跳一跳还有16款微信小游戏可以玩
    小游戏里潜藏着600亿的大市场
  • 原文地址:https://www.cnblogs.com/xixixing/p/15773290.html
Copyright © 2011-2022 走看看