日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

二维码Data Matrix的解码实现(zxing-cpp)

發布時間:2023/11/27 生活经验 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 二维码Data Matrix的解码实现(zxing-cpp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

二維碼Data Matrix的介紹可以參考http://blog.csdn.net/fengbingchun/article/details/44279967?,以下是通過zxing-cpp開源庫實現的對Data Matrix進行解碼的測試代碼:

#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 <opencv2/opencv.hpp>#include "zxing/MatSource.h"static void utf8_to_gbk(const char* utf8, char* gbk) {const int maxlen = 128;wchar_t unicode_str[maxlen];int outlen = MultiByteToWideChar(CP_UTF8, 0, utf8, strlen(utf8), unicode_str, maxlen);outlen = WideCharToMultiByte(CP_ACP, 0, unicode_str, outlen, gbk, 128, NULL, NULL);gbk[outlen] = '\0';
}int test_DataMatrix_decode()
{std::string image_name = "E:/GitCode/BarCode_Test/test_images/data_matrix_encode.jpg";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::datamatrix::DataMatrixReader);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::DATA_MATRIX_HINT)));std::string txt = "E:/GitCode/BarCode_Test/test_images/data_matrix_encode.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);char tmp[128];utf8_to_gbk(str1.c_str(), tmp);std::string ret = std::string(tmp);fprintf(stderr, "actual        result: %s\n", ret.c_str());std::string str2 = result->getText()->getText();fprintf(stdout, "recognization result: %s\n", str2.c_str());if (ret.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



總結

以上是生活随笔為你收集整理的二维码Data Matrix的解码实现(zxing-cpp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。