二维码PDF417简介及其解码实现(zxing-cpp)
2024-10-11 18:06:46
二维码PDF417是一种堆叠式二维条码。PDF417条码是由美国SYMBOL公司发明的,PDF(Portable Data File)意思是“便携数据文件”。组成条码的每一个条码字符由4个条和4个空共17个模块构成,故称为PDF417条码。 PDF417条码需要有417解码功能的条码阅读器才能识别。PDF417条码最大的优势在于其庞大的数据容量和极强的纠错能力。
PDF417条码是一种高密度、高信息含量的便携式数据文件,是实现证件及卡片等大容量、高可靠性信息自动存储、携带并可用机器自动识读的理想手段。
PDF417条码可表示数字、字母或二进制数据,也可表示汉字。一个PDF417条码最多可容纳1850 个字符或1108 个字节的二进制数据,如果只表示数字则可容纳2710 个数字。PDF417的纠错能力分为9级,级别越高,纠正能力越强。由于这种纠错功能,使得污损的PDF417条码也可以正确读出。我国已制定了PDF417码的国家标准。
二维码PDF417可应用在:证件管理、执照年检、报表管理、机电产品的生产和组配线、银行票据管理及行包、货物的运输和邮递。
以下是通过zxing-cpp开源库实现的对二维码PDF417进行解码的测试代码:
#include "funset.hpp" #include <string> #include <fstream> #include <Windows.h> #include <zxing/LuminanceSource.h> #include <zxing/common/Counted.h> #include <zxing/Reader.h> #include <zxing/aztec/AztecReader.h> #include <zxing/common/GlobalHistogramBinarizer.h> #include <zxing/DecodeHints.h> #include <zxing/datamatrix/DataMatrixReader.h> #include <zxing/MultiFormatReader.h> #include <zxing/pdf417/PDF417Reader.h> #include <opencv2/opencv.hpp> #include "zxing/MatSource.h" int test_PDF417_decode() { std::string image_name = "E:/GitCode/BarCode_Test/test_images/PDF417.png"; cv::Mat matSrc = cv::imread(image_name, 1); if (!matSrc.data) { fprintf(stderr, "read image error: %s", image_name.c_str()); return -1; } cv::Mat matGray; cv::cvtColor(matSrc, matGray, CV_BGR2GRAY); zxing::Ref<zxing::LuminanceSource> source = MatSource::create(matGray); int width = source->getWidth(); int height = source->getHeight(); fprintf(stderr, "image width: %d, height: %d\n", width, height); zxing::Ref<zxing::Reader> reader; reader.reset(new zxing::pdf417::PDF417Reader); zxing::Ref<zxing::Binarizer> binarizer(new zxing::GlobalHistogramBinarizer(source)); zxing::Ref<zxing::BinaryBitmap> bitmap(new zxing::BinaryBitmap(binarizer)); zxing::Ref<zxing::Result> result(reader->decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::PDF_417_HINT))); std::string txt = "E:/GitCode/BarCode_Test/test_images/PDF417.txt"; std::ifstream in(txt); if (!in.is_open()) { fprintf(stderr, "fail to open file: %s\n", txt.c_str()); return -1; } std::string str1; std::getline(in, str1); fprintf(stderr, "actual result: %s\n", str1.c_str()); std::string str2 = result->getText()->getText(); fprintf(stdout, "recognization result: %s\n", str2.c_str()); if (str1.compare(str2) == 0) { fprintf(stderr, "===== recognition is correct =====\n"); } else { fprintf(stderr, "===== recognition is wrong =====\n"); return -1; } in.close(); return 0; }
测试图像如下:
测试结果如下:
GitHub:https://github.com/fengbingchun/Barcode_Test
最新文章
- js⑤
- myeclipse10中文注释乱码问题
- CSS3-基于浮动的布局,响应式WEB设计,定位网页上的元素,设计打印页面的css技术
- Arbitrage(bellman_ford)
- android 通过TimePickerDialog修改时间
- php 变量
- Redis全面介绍
- javabean内省
- [HTTP] PHP 实现 HTTP Server 原理
- Python读写文件你真的了解吗?
- sed从入门到深入的使用心得
- 实战Asp.Net Core:DI生命周期
- elasticsearch和mysql排序问题
- redis集群redis-cloud搭建
- API网关之Kong网关简介
- MySQL优化:explain using temporary
- jQuery 学习笔记2 点击时弹出一个对话框
- Java 打开Excel,往Excel中存入值,保存的excel格式分别是xls和xlsx
- arcgis for silverlight 地图放大到某个点或者几何对象
- [Uliweb]-URL映射
热门文章
- 第六章 函数、谓词、CASE表达式 6-1 各种各样的函数
- Ubuntu做Tomcat服务:insserv: warning: script &#39;tomcat&#39; missing LSB tags and overrides
- systemd 之 systemctl
- Python学习---django-debug-tools安装
- MVC5开发环境的配置
- list(range())--------range创建一个list列表 遍历索引range(len()) 和 list(range())创建列表
- PHP SPL神器实现堆排序
- zookeeper环境搭建.md
- PHP获取视频的第一帧与时长
- Kafka设计解析(十)Kafka如何创建topic