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;
}
测试图像如下:
测试结果如下: