二维码Aztec简介及其解码实现(zxing-cpp)
2024-08-26 14:13:58
Aztec Code是1995年,由Hand HeldProducts公司的Dr. Andrew Longacre设计。它是一种高容量的二维条形码格式。它可以对ASCII和扩展ASCII码进行编码。当使用最高容量和25%的纠错级别的時候,Aztec可以对3000个字符或者3750个数字进行编码。
Aztec的矩阵大小在15 X 15和151 X 151之间变化。每个最小单位非黑即白。它独特的位于正中的模式识别标志和安置算法使Aztec看起来像个旋涡一样。
Aztec打印解决方案允许用户选择大小和纠错级别。一共有36中不同的格式供选择,此外还有19种纠错级别可供选择,默认纠错级别是5级23%。高纠错级别意味着更少的数据容量和更小的误码机会。
以下是通过zxing-cpp开源库实现的对Aztec二维码进行解码的测试代码:
#include "funset.hpp" #include <string> #include <fstream> #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 <opencv2/opencv.hpp> #include "zxing/MatSource.h" int test_Aztec_decode() { std::string image_name = "E:/GitCode/BarCode_Test/test_images/Aztec_tableShifts.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::aztec::AztecReader); 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::AZTEC_HINT))); std::string txt = "E:/GitCode/BarCode_Test/test_images/Aztec_tableShifts.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
最新文章
- Entity Framework 数据库初始化四种策略
- Android属性动画之第一重修炼总结
- mysqlbinlog恢复数据-update20140820
- java中DriverManager跟DataSource获取getConnection有什么不同?
- SQL注入式攻击
- 七牛云覆盖上传 php
- sql 字段先计算后再拿比对的字段进行比对 效率提升100倍
- 关于Scrapy框架的安装
- 原型扩展的方法解决IE和Firefox的Js兼容问题
- python2和python3中的类
- Servlet学习应该注意的几点
- 拼写纠错的利器,BK树算法
- (MonoGame从入门到放弃-3)-放弃MonoGame
- CSS学习笔记五:display,position区别
- IntelliJ IDEA 打开项目红色
- Unicode 与 Unicode Transformation Format(UTF-8 / UTF-16 / UTF-32)
- BZOJ2213[Poi2011]Difference——DP
- 爬虫概念 requests模块
- 101. Symmetric Tree(判断二叉树是否对称)
- linux(7)
热门文章
- 关于 ExpressRoute 的虚拟网络网关
- teradata 查询创建表的时间
- MySQL Group Replication配置
- SQL SERVER Management Studio编写SQL时没有智能提示的解决方式
- 在虚拟机里安装linux(centos 6.5)系统
- MFC调试时可以,使用生产的exe时,显示未响应解决方案
- 面对对象程序设计_task2_1001.A+B Format (20)
- chrome开发者工具那点事
- Ceph块存储介绍
- Nginx变量.md