二维码Aztec简介及其解码实现(zxing-cpp)
生活随笔
收集整理的這篇文章主要介紹了
二维码Aztec简介及其解码实现(zxing-cpp)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
總結
以上是生活随笔為你收集整理的二维码Aztec简介及其解码实现(zxing-cpp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Caffe中Layer注册机制
- 下一篇: 二维码Data Matrix的解码实现(