ZBar 是款桌面电脑用条形码/二维码扫描工具

windows平台python 2.7环境编译安装zbar

 

最近一个项目需要识别二维码,找来找去找到了zbar和zxing,中间越过无数坑,总算基本上弄明白,分享出来给大家。

一、zbar官方介绍

ZBar 是款桌面电脑用条形码/二维码扫描工具,支持摄像头及图片扫描,支持多平台,例如 iPhone,Andriod 手机,同时 ZBar封装了二维码扫描的 API 开发包。

ZBar 目前条码类型有:EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 and QR Code.

从上可以看出,zbar有挺多优势,封装了API,支持多平台,支持多种条码类型,包括一维、二维码。

具体主页:http://zbar.sourceforge.net/

二、zbar的python安装

进入https://pypi.python.org/pypi/zbar,可以看到最新版本是0.10,提供源码以及python2.5、python2.6下的exe版本。

File Type Py Version Uploaded on Size
zbar-0.10.tar.bz2 (md5pgp) Source   2009-11-10 15KB
zbar-0.10.tar.gz (md5pgp) Source   2009-11-10 18KB
zbar-0.10.win32-py2.5.exe (md5pgp) MS Windows installer 2.5 2009-11-10 74KB
zbar-0.10.win32-py2.6.exe (md5pgp) MS Windows installer 2.6 2009-11-10 205KB
zbar-0.10.zip (md5pgp) Source   2009-11-10 31K
 

结论:没有whl,没有python2.7的exe安装,更不奢望64位版本之类。

1、pypi网址,找whl或者exe安装包

百度找到非官方发布的python2.7下zbar安装文件,https://github.com/jacobvalenta/zbar-py27-msi/blob/master/zbar-0.10.win32-py2.7_2.msi。

实测可用,这里为了说明pypi的编译过程,不使用该方案。

2、pypi源码安装

2.1、配置mingw编译环境

windows系统安装并配置mingw编译器,是另一个大坑,爬坑的过程不细说,简要描述如下:

1、下载mingw 5.1.6 ,地址如下:http://d1.rsdown.cn/soft1/mingw5.1.6.zip
2、解压后,双击其中的mingw.exe进行安装,选择常用的安装包,例如gcc等。
3、配置mingw安装路径,参看:http://blog.csdn.net/wangrouyi/article/details/7454687(注意,这个说明中的mingw是按照在d:\mingw下,如果你是安装在c盘,则要改成c:\mingw。)

右击我的电脑,点属性->高级->环境变量。然后:
1)、在PATH里加入D:\MinGW\bin,记得,如果里面还有其他的变量,记得要加个分号啊,分号得在英文输入模式下输入的。
2)、新建LIBRARY_PATH变量,如果有的话,在值中加入D:\MinGW\lib,这是标准库的位置。
3)、新建C_INCLUDEDE_PATH变量,值设为D\MinGW\include。
4)、新建CPLUS_INCLUDE_PATH变量,值为D\MinGW\include\c++\3.4.5;D:\MinGW\include\c++\3.4.5;D:\MinGW\include\c++\3.4.5\backward;D:\MinGW\include。

4、python中配置mingw编译器。

在C:\Python27\Lib\distutils下新建或者修改distutils.cfg文件,内容如下:

[build]
compiler=mingw32

2.2、pip安装(pip install zbar),下面开始逐项排雷。

1、pip install zbar,出现c语言编译错误,没有找到zbar.h头文件(下图中红色字体部分)

C:\Users\zou>pip install zbar
Collecting zbar
Downloading http://mirrors.aliyun.com/pypi/packages/33/54/cc5819efc9ee7e34b60b41e1d2d4753b6dd0c26a41c9a552611f66aa106e/zbar-0.10.tar.bz2
Installing collected packages: zbar
Running setup.py install for zbar ... error
Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\joshua~1\\appdata\\local\\temp\\pip-build-pnikpa\\zbar\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\joshua~1\appdata\local\temp\pip-2chu03-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'zbar' extension
creating build
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\python27\include -Ic:\python27\PC -c zbarmodule.c -o build\temp.win32-2.7\Release\zbarmodule.o
In file included from zbarmodule.c:24:
zbarmodule.h:26:18: zbar.h: No such file or directory
In file included from zbarmodule.c:24
:
zbarmodule.h:37: error: `ZBAR_ERR_NUM' undeclared here (not in a function)
zbarmodule.h:67: error: syntax error before "zbar_image_t"
zbarmodule.h:67: warning: no semicolon at end of struct or union
zbarmodule.h:69: error: syntax error before '}' token
zbarmodule.h:69: warning: type defaults to `int' in declaration of `zbarImage'
zbarmodule.h:69: warning: data definition has no type or storage class

2、进入https://github.com/ZBar/ZBar/tree/master/python 目录,查看python下的说明,发现如下文字:

To install this module type the following::

   python setup.py install

Dependencies
------------ This module requires the ZBar Bar Code Reader, which may be obtained
from: * http://zbar.sourceforge.net/ Windows users please note: the module *will NOT load* unless the ZBar
library DLL (currently libzbar-0.dll) is available in your Windows system
PATH!

简单翻译一下:

a、python zbar安装方法:python setup.py install

b、python zbar需要zbar reader,zbar reader可以从http://zbar.sourceforge.net/网址下载到。

c、windows平台,需要zbar dll,最新版本名字为libzbar-0.dll 。

3、进入http://zbar.sourceforge.net/download.html,下载windows下的zbar reader执行程序。

Windows Installer

Note that the Windows port is in an unstable, testing phase. If you do try it out, please let us know how well it's working for you and open a support request if you encounter any problems.

The Windows Installation Guide has detailed instructions for installing and getting started with ZBar on Windows.

ZBar 0.10 Windows installer

The Windows installer now includes pre-built binaries of the dependencies (ImageMagick et al). Copyright, license, and source code details for these libraries may be found in the README included with the distribution.

Windows binaries for the Python module are available from PyPI

具体网址:https://jaist.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10-setup.exe ,下载后安装zbar  reader执行程序

4、安装zbar reader,默认路径 C:\Program Files (x86)\ZBar 。

在C:\Program Files (x86)\ZBar\lib 目录下,果然找到libzbar-0.lib库文件。

在C:\Program Files (x86)\ZBar\include 目录下,果然找到zbar.h头文件。

5、从https://pypi.python.org/pypi/zbar下载zbar.0.1.0.zip源码文件,解压到d:\src目录,修改其中的setup.py文件,指向include、lib目录。

    ext_modules = [
Extension('zbar', [
'zbarmodule.c',
'enum.c',
'exception.c',
'symbol.c',
'symbolset.c',
'symboliter.c',
'image.c',
'processor.c',
'imagescanner.c',
'decoder.c',
'scanner.c',
],
         library_dirs = ['C:\Program Files (x86)\ZBar\lib' ] ,
            libraries= ['libzbar-0'],
            include_dirs = ['C:\Program Files (x86)\ZBar\include'],
),

6、手工执行执行安装。

d:\src\>python setup.py install
running install
running build
running build_ext
building 'zbar' extension
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c zbarmodule.c -o build\temp.win32-2.7\Release\zbarmodule.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c enum.c -o build\temp.win32-2.7\Release\enum.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c exception.c -o build\temp.win32-2.7\Release\exception.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c symbol.c -o build\temp.win32-2.7\Release\symbol.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c symbolset.c -o build\temp.win32-2.7\Release\symbolset.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c symboliter.c -o build\temp.win32-2.7\Release\symboliter.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c image.c -o build\temp.win32-2.7\Release\image.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c processor.c -o build\temp.win32-2.7\Release\processor.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c imagescanner.c -o build\temp.win32-2.7\Release\imagescanner.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c decoder.c -o build\temp.win32-2.7\Release\decoder.o
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\ZBar\include" -Ic:\python27\include -Ic:\python27\PC -c scanner.c -o build\temp.win32-2.7\Release\scanner.o
writing build\temp.win32-2.7\Release\zbar.def
c:\mingw\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\zbarmodule.o build\temp.win32-2.7\Release\enum.o build\temp.win32-2.7\Release\exception.o build\temp.win32-2.7\Release\symbol.o
build\temp.win32-2.7\Release\symbolset.o build\temp.win32-2.7\Release\symboliter.o build\temp.win32-2.7\Release\image.o build\temp.win32-2.7\Release\processor.o build\temp.win32-2.7\Release\imagescanner.o
build\temp.win32-2.7\Release\decoder.o build\temp.win32-2.7\Release\scanner.o build\temp.win32-2.7\Release\zbar.def
"-LC:\Program Files (x86)\ZBar\lib" -Lc:\python27\libs -Lc:\python27\PCbuild -Lc:\python27\PC\VS9.0 -llibzbar-0 -lpython27 -lmsvcr90 -o build\lib.win32-2.7\zbar.pyd
running install_lib
copying build\lib.win32-2.7\zbar.pyd -> c:\python27\Lib\site-packages
running install_egg_info
Writing c:\python27\Lib\site-packages\zbar-0.10-py2.7.egg-info

至此,编译并安装成功。

注意,上文中红色字体部分,Include目录增加了C:\Program Files (x86)\ZBar\include,Lib目录增加了C:\Program Files (x86)\ZBar\lib目录 。

至于  libzbar-0 是因为lib目录中是已经有lib文件。

三、总结

总结上述排雷的过程,无非是对c语言编译器的一点点基础,其次仔细查看错误,仔细查找说明文件。

ZBar 是款桌面电脑用条形码/二维码扫描工具的更多相关文章

  1. 使用Zxing开发Air版二维码扫描工具

    简介实现的核心要点和几个须要注意的问题: 使用开源类库:Zxing,微信也是用的这个.下载地址:http://code.google.com/p/zxing/ as版:https://github.c ...

  2. Qt之二维码扫描

    简述 二维码(QR Code)是用某种特定的几何图形按一定规律在平面(二维方向)分布的黑白相间的图形记录数据符号信息的.是所有信息数据的一把钥匙.应用十分广泛,如:产品防伪/溯源.广告推送.网站链接. ...

  3. iOS 原生二维码扫描和生成

    代码地址如下:http://www.demodashi.com/demo/12551.html 一.效果预览: 功能描述:WSLNativeScanTool是在利用原生API的条件下封装的二维码扫描工 ...

  4. Opencv+Zbar二维码识别(标准条形码/二维码识别)

    使用Opencv+Zbar组合可以很容易的识别图片中的二维码,特别是标准的二维码,这里标准指的是二维码成像清晰,图片中二维码的空间占比在40%~100%之间,这样标准的图片,Zbar识别起来很容易,不 ...

  5. android利用zbar二维码扫描-(解决中文乱码及扫描区域定义)

    写在最前(这是对上一篇博文的问题做的更新[android利用zbar二维码扫描]) project下载   zbarLib编译project  project下载0积分 bug 在2.3的系统中Hol ...

  6. 二维码扫描利用ZBar实现

    上次是根据系统的属性自己封装的一个二维码扫描,这次给大家介绍一下基于ZBar集成的类似于QQ二维码扫描界面的二维码扫描的效果.                                     ...

  7. Android快速实现二维码扫描--Zbar

    Android中二维码扫描的最常用库是zxing和zbar,上一篇<Android快速实现二维码扫描–Zxing>介绍了Zxing.这次说Zbar,Zbar速度极快,我就比较常用,项目地址 ...

  8. DevExpress 使用条形码二维码控件打印

    参考文章: https://www.cnblogs.com/wuhuacong/p/6112976.html 转载请注明出处:撰写人:伍华聪 其实主要是二维码的实现,在使用条形码控件时,又一个属性Sy ...

  9. vue项目条形码和二维码生成工具试用

    项目开发需要,优惠券分不同类型,简单的使用id生成条形码供店铺使用,麻烦点的需要多个字段的就需要使用二维码来展示了,对应的效果如下 条形码(一维码)使用工具code128 需引入code128.js ...

随机推荐

  1. ArcGIS Engine 线段绘制

    转自ArcGIS Engine 线段绘制研究 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x ...

  2. CMake编译Makefile

    以编译Libtif文件为例: 你可以用CMake编译libtiff,超简单,两个步骤. 参考文章 CharlesSimonyi,libtiff库的问题的答复

  3. 关于java中String的一点理解

      String类是java的最基本类之中的一个,非常好的掌握它的原理非常是必要的!   1.String的Final类型的.是不可继承 的.final类默认的方法都为final类型,保证了方法不能被 ...

  4. Android中使用HttpClient实现HTTP通信效果

    HTTP通信,这一案例在操作的时候遇到N多种种问题,是前面看过几个实例里面最麻烦的一个.由于没有系统的接触过JAVA,所以出了非常多错误,也无从下手解决,这里经过对错误的检索实现了HTTP通信,以做记 ...

  5. [C/C++]_[0基础]_[static_cast,reinterpret_cast,dynimic_cast的使用场景和差别]

    场景: 1. C++的对象差别于C的原因是他们能够有继承关系, 方法有重载, 覆盖关系等, 他们的对象内存数据结构因此也比較复杂. 2. 非常多情况下我们须要一个父类来存储子类的指针对象进行通用方法的 ...

  6. java中volatile关键字的含义--volatile并不能做到线程安全

    在Java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  7. Dcloud课程1 APP的架构有哪些

    Dcloud课程1 APP的架构有哪些 一.总结 一句话总结:B/S架构和C/S构架 1.APP的分类? 主流的四大APP系统:1.苹果ios系统版本,开发语言是Objective-C:2.微软Win ...

  8. JAVA开发类似冒险岛的游戏Part1

    JAVA开发类似冒险岛的游戏Part1 一.总结 二.JAVA开发类似冒险岛的游戏Part1 初学嘛) ,不过总的来说这个程序还是很有意思的.这里我重新再整理了一下,希望能帮助到其他想要开发类似程序的 ...

  9. (转) 设置sqlplus中的退格键

    转自:http://blog.itpub.net/26110315/viewspace-717249/ 有些时候当你使用sqlplus登录到数据库中的时候,敲错了命令想要删除修改的时候,发现以前敲入的 ...

  10. js匿名函数(变量加括号就是函数)

    js匿名函数(变量加括号就是函数) 一.总结 变量加括号就是函数,而函数的括号是用来传参的 1.类比:以正常函数去想匿名函数,匿名函数比正常函数只是少了函数名,本质还是一样,该怎么传参还是怎么传参,小 ...