二维码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;
}

测试图像如下:

输出结果如下:

GitHubhttps://github.com/fengbingchun/Barcode_Test

二维码Data Matrix的解码实现(zxing-cpp)的更多相关文章

  1. 二维码Data Matrix编码、解码使用举例

    二维码Data Matrix的介绍见: http://blog.csdn.net/fengbingchun/article/details/44279967  ,这里简单写了个生成二维码和对二维码进行 ...

  2. (zxing.net)二维码Data Matrix的简介、实现与解码

    一.简介 Data Matrix 二维条码原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于1989年发明.Data-Matri ...

  3. 二维码Data Matrix简单介绍及在VS2010中的编译

    Data Matrix 二维条码原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于1989年发明.Data-Matrix二维条码 ...

  4. 二维码的妙用:通过Zxing实现wifi账号password分享功能

    二维码是搭载信息的一种载体,通过二维码能够传递名片.网址.商品信息等,本文讲到二维码的第二种妙用:通过二维码实现wifi账号和password分享. 关于二维码的基础知识,请訪问:二维码的生成细节和原 ...

  5. zxing二维码的生成与解码(C#)

    ZXing是一个开源Java类库用于解析多种格式的1D/2D条形码.目标是能够对QR编码.Data Matrix.UPC的1D条形码进行解码. 其提供了多种平台下的客户端包括:J2ME.J2SE和An ...

  6. 二维码PDF417简介及其解码实现(zxing-cpp)

    二维码PDF417是一种堆叠式二维条码.PDF417条码是由美国SYMBOL公司发明的,PDF(Portable Data File)意思是"便携数据文件".组成条码的每一个条码字 ...

  7. 二维码Aztec简介及其解码实现(zxing-cpp)

    Aztec Code是1995年,由Hand HeldProducts公司的Dr. Andrew Longacre设计.它是一种高容量的二维条形码格式.它可以对ASCII和扩展ASCII码进行编码.当 ...

  8. 使用Zint和Zxing实现二维码的编码与解码(Using open-source tools to generate and decode Q-R code)

    1.Zint生成二维码 http://sourceforge.net/projects/zint/ [1]从上述站点下载Zint工具 [2]安装Zint工具 [3]使用Zint工具生成二维码,注意选择 ...

  9. 二维码、条形码扫描——使用Google ZXing

    我在项目中用到了二维码扫描的技术,用的是Google提供的ZXing开源项目,它提供二维码和条形码的扫描.扫描条形码就是直接读取条形码的内容,扫描二维码是按照自己指定的二维码格式进行编码和解码. 可以 ...

随机推荐

  1. [翻译] NSDate-TimeAgo

    NSDate-TimeAgo https://github.com/kevinlawler/NSDate-TimeAgo NSDate+TimeAgo has merged with DateTool ...

  2. 使用CAReplicatorLayer [1]

    使用CAReplicatorLayer [1] 说明 https://developer.apple.com/library/ios/documentation/GraphicsImaging/Ref ...

  3. Python学习---Django拾遗180328

    Django之生命周期 前台发送URL请求到Django的中间件进行内容校验,完成校验后到达路由映射文件url.py,然后调用视图函数views.py里面的函数进行内容处理[ 1.操作数据库进行数据读 ...

  4. idea指定SpringBoot启动.properties文件

    比如我的项目下有2个.properties文件,一个是application.properties,一个是application-local.properties,在本地的时候想指定用applicat ...

  5. 铁乐学python_day22_面向对象编程4

    以下内容大部分摘自博客http://www.cnblogs.com/Eva-J/ 封装 [封装]隐藏对象的属性和实现细节,仅对外提供公共访问方式. [好处] 将变化隔离: 便于使用: 提高复用性: 提 ...

  6. springsource-tool-suite插件的在线安装

      1 首先,确定你现在使用的eclipse属于哪个版本? 查看自己的eclipse平台的版本(我的eclipse平台版本是4.3)       2 根据eclipse版本,选择插件的版本 官网:ht ...

  7. Xpath注入学习

    xpath简介: 提到xpath就要先说下xml,xml意为可扩展标记语言,简单来说就是一种存储数据的标准格式,可以把他视为一个小型的数据库,他可以解决数据在网上传输的标准问题.是一种比数据库更具通用 ...

  8. Cloudera Manager 4.6 安装部署hadoop CDH集群

    Cloudera Manager 4.6 安装详解 1. Cloudera Manager介绍 1.1. 功能介绍 Cloudera Manager是一个针对hadoop集群的管理工具,功能包括:cd ...

  9. python第十八课——常用内置函数

    常用内置函数:round(): print(round(3.14),round(3.99)) print(round(3145.926,-2),round(413.575,2)) abs(): pri ...

  10. python第十四课--排序及自定义函数之自定义函数(案例四)

    整理:4中最常见的自定义函数模型1).无参无返回值2).无参有返回值3).有参无返回值4).有参有返回值 #定义无参无返回值自定义函数 def func1(): print('hello method ...