内容简介:ZBar是一个开源 C 条形码阅读库,具有C ++,Python,Perl和Ruby 接口。它也作为命令行应用程序和iPhone应用程序在Linux和Microsoft Windows上实现。具有如下特点:首先先到zbar官网下载安装包,
ZBar是一个开源 C 条形码阅读库,具有C ++,Python,Perl和 Ruby 接口。它也作为命令行应用程序和iPhone应用程序在 Linux 和Microsoft Windows上实现。
具有如下特点:
- 图像扫描
- 实时扫描视频流
- C ++,Python,Perl和Ruby的api接口
- Qt,GTK +和PyGTK GUI的api接口
- 对EAN-13,UPC-A,UPC-E,EAN-8,Code 128,Code 39,Interleaved 2 of 5和QR码 符号的识别
安装
下载
首先先到zbar官网下载安装包, 下载链接
安装
下载后,点击安装程序,这是一个自解压程序,类似opencv的安装程序,安装到自己所需要的目录就可以。
安装步骤除了两个步骤,其它都按照默认点就好。一个是选择你自己需要安装的路径,默认的安装路径C盘
另一个步骤则是到这里,选择头文件(Headers)和库文件目录(Libraries)的创建,用以接下来的配置。
配置
配置过程与opencv的配置类似,步骤是一样的。
这是自解压安装的文件夹,其中bin、include、lib目录是配置需要用到的。
- 环境变量的配置, bin目录添加到系统的path
- 打开vs,新建空项目,添加main.cpp文件。在属性管理器(选x86,亲测不支持x64),右键新建属性表。
- 编辑新建的属性表。 vc++包含目录填include文件夹路径。库目录填lib文件夹路径。链接器->输入->附加依赖项。填写libzbar-0.lib
测试
安装文件夹里面有官方示例代码如下。
#include<iostream>
#include<Magick++.h>
#include<zbar.h>
#defineSTR(s) #s
using namespace std;
using namespace zbar;
int main(int argc, char **argv)
{
if(argc < 2) return(1);
#ifdefMAGICK_HOME
// http://www.imagemagick.org/Magick++/
// under Windows it is necessary to initialize the ImageMagick
// library prior to using the Magick++ library
Magick::InitializeMagick(MAGICK_HOME);
#endif
// create a reader
ImageScanner scanner;
// configure the reader
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
// obtain image data
Magick::Imagemagick(argv[1]); // read an image file
int width = magick.columns(); // extract dimensions
int height = magick.rows();
Magick::Blob blob; // extract the raw data
magick.modifyImage();
magick.write(&blob, "GRAY", 8);
const void *raw = blob.data();
// wrap image data
Imageimage(width, height,"Y800", raw, width * height);
// scan the image for barcodes
int n = scanner.scan(image);
// extract results
for(Image::SymbolIterator symbol = image.symbol_begin();
symbol != image.symbol_end();
++symbol) {
// do something useful with results
cout << "decoded " << symbol->get_type_name()
<< " symbol \"" << symbol->get_data() << '"' << endl;
}
// clean up
image.set_data(NULL, 0);
return(0);
}
但是示例代码中使用了imageMagick++这个第三方库。没接触使用过,这里就稍加修改,使用opencv代替imageMagick++读入图片的功能。
#include<opencv2/opencv.hpp>
#include<iostream>
#include<zbar.h>
using namespace std;
using namespace zbar;
int main(int argc, char **argv)
{
// create a reader
ImageScanner scanner;
// configure the reader
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
// obtain image data
cv::Mat image = cv::imread("wechat.jpg"); // read an image file
if (image.empty()) return -1;
int width = image.rows; // extract dimensions
int height = image.cols;
cv::Mat img_gray;
cv::cvtColor(image, img_gray, cv::COLOR_BGR2GRAY);
uchar *raw = (uchar*)img_gray.data;
// wrap image data
Imageimage_zbar(width, height,"Y800", raw, width * height);
// scan the image for barcodes
int n = scanner.scan(image_zbar);
if (image_zbar.symbol_begin() == image_zbar.symbol_end())
{
cout << "Failed to scan, please check the image!" << endl;
}
// extract results
for (Image::SymbolIterator symbol = image_zbar.symbol_begin();
symbol != image_zbar.symbol_end();
++symbol) {
// do something useful with results
cout << "decoded " << symbol->get_type_name()
<< " symbol \"" << symbol->get_data() << '"' << endl;
}
cv::imshow("barcode", image);
cv::waitKey(0);
// clean up
image_zbar.set_data(NULL, 0);
return(0);
}
以上所述就是小编给大家介绍的《zbar条形码识别库vs配置》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- iOS 扫描二维码/条形码
- iOS 生成二维码/条形码
- 小程序中生成二维码和条形码
- Seppiko Chart 1.5 已经发布,Java 条形码库
- 用OpenCV和Python识别二维码和条形码
- 条形码处理类库 ZXing 3.3.3 发布,支持 Java 9
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Analytics 2.0
Avinash Kaushik / Sybex / 2009-10-26 / USD 39.99
The bestselling book Web Analytics: An Hour A Day was the first book in the analytics space to move beyond clickstream analysis. Web Analytics 2.0 will significantly evolve the approaches from the fir......一起来看看 《Web Analytics 2.0》 这本书的介绍吧!