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

int test_data_matrix_encode()
{
	std::string str = "中国_abc_DEF_123_@#$!HTTP://WWW.LIBDMTX.ORG";

	DmtxEncode* enc = dmtxEncodeCreate();
	assert(enc != NULL);
	int ret = dmtxEncodeDataMatrix(enc, strlen(str.c_str()), (unsigned char*)str.c_str());
	assert(ret == 1);

	int width = dmtxImageGetProp(enc->image, DmtxPropWidth);
	int height = dmtxImageGetProp(enc->image, DmtxPropHeight);
	int bytesPerPixel = dmtxImageGetProp(enc->image, DmtxPropBytesPerPixel);
	fprintf(stderr, "image width: %d, image height: %d, channels: %d\n", width, height, bytesPerPixel);
	assert(bytesPerPixel == 1 || bytesPerPixel == 3 || bytesPerPixel == 4);

	cv::Mat mat;
	if (bytesPerPixel == 1)
		mat = cv::Mat(height, width, CV_8UC1);
	else if (bytesPerPixel == 3)
		mat = cv::Mat(height, width, CV_8UC3);
	else
		mat = cv::Mat(height, width, CV_8UC4);

	mat.data = enc->image->pxl;

	std::string image_name = "E:/GitCode/BarCode_Test/test_images/data_matrix_encode.jpg";
	cv::imwrite(image_name, mat);

	dmtxEncodeDestroy(&enc);

	return 0;
}

int test_data_matrix_decode()
{
	std::string image_name = "E:/GitCode/BarCode_Test/test_images/data_matrix_encode.jpg";
	cv::Mat mat = cv::imread(image_name, 1);
	if (!mat.data) {
		fprintf(stderr, "read image error\n");
		return -1;
	}

	int width = mat.cols;
	int height = mat.rows;
	int channels = mat.channels();

	DmtxImage* img = dmtxImageCreate(mat.data, width, height, DmtxPack24bppRGB);
	if (!img) {
		fprintf(stderr, "dmtx image create fail\n");
		return -1;
	}

	DmtxDecode* dec = dmtxDecodeCreate(img, 1);
	if (!dec) {
		fprintf(stderr, "dmtx decode create fail\n");
		return -1;
	}

	DmtxRegion* reg = dmtxRegionFindNext(dec, nullptr);
	if (!reg) {
		fprintf(stderr, "dmtx region fail\n");
		return -1;
	}

	DmtxMessage* msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
	if (!msg) {
		fprintf(stderr, "dmtx decode matrix region fail\n");
		return -1;
	}

	std::string str(reinterpret_cast<char*>(msg->output));
	fprintf(stderr, "decode result: %s\n", str.c_str());

	dmtxMessageDestroy(&msg);
	dmtxRegionDestroy(&reg);
	dmtxDecodeDestroy(&dec);
	dmtxImageDestroy(&img);

	return 0;
}

其中test_data_matrix_encode函数用来生成二维码,如下:

test_data_matrix_decode函数用来简析上面生成的二维码,执行结果如下:

可看出,前后结果是一致的。

GitHubhttps://github.com/fengbingchun/BarCode_Test

二维码Data Matrix编码、解码使用举例的更多相关文章

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

    二维码Data Matrix的介绍可以参考http://blog.csdn.net/fengbingchun/article/details/44279967 ,以下是通过zxing-cpp开源库实现 ...

  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. Java实现二维码QRCode的编码和解码

    涉及到的一些主要类库,方便大家下载: 编码lib:Qrcode_swetake.jar   (官网介绍-- http://www.swetake.com/qr/index-e.html) 解码lib: ...

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

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

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

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

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

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

  8. java 二维码原理以及用java实现的二维码的生成、解码(转)

    http://blog.csdn.net/songylwq/article/details/8643948 http://sjsky.iteye.com/blog/1136934 http://bbs ...

  9. C#实现二维码生成与解码

    前几天公司内部分享了一个关于二维码的例子,觉得挺好玩的,但没有提供完整的源码.有时候看到一个好玩的东西,总想自己Demo一个,于是抽空就自己研究了一下. 一.二维码的原理 工欲善其事,必先利其器.要生 ...

随机推荐

  1. Oracle EBS PO 接受入库

  2. A B C D类网络地址

    A类网络地址(红色为网络地址,黑色为主机地址): 下限:0000 0001.0000 0000.0000 0000.0000 0000(1.0.0.0) 上限:0111 1110.1111 1111. ...

  3. c++与matlab联合编程,调用Deploytool 生成exe文件和dll文件(转)

    转自:http://www.cnblogs.com/xlw1219/archive/2012/12/25/2832222.html 首先必须知道联合编程需要知道的一些命令解释: mcc 的作用是将 . ...

  4. 成为技术领导者笔记--领导的MOI模型

    一. 想让周围环境发生变化,环境必须包含三个条件: M:激励(Motivation)---有奖品或有困难,这样才对相关人员有推动力或吸引力. O:组织(organization)---利用现有的组织结 ...

  5. java内部类案例

    实现键值对的存储输出 import java.util.Arrays; public class EntryDemoTest { //实现键值对的存储 public static void main( ...

  6. C#基础学习之委托的理解和应用

    委托的使用和语法定义 委托的使用是由四步来完成的,依次为:声明委托.创建委托对象.委托关联方法.调用 我们用一个例子来说明这四步如何操作,我们完成一个老板委托员工写报告的实例,看如何实现. 首先我们应 ...

  7. Type Safety and Type Inference

    Swift is a type-safe language. A type safe language encourages you to be clear about the types of va ...

  8. Python全栈开发:list 、tuple以及dict的总结

    总结: 列表:增:append(),inset(),extend() 删:pop(),remove(),clear(),del 改:a.通过指定元素和切片重新赋值.b.可以使用repelace替换列表 ...

  9. Sublime Text常用设置之个人配置

    一.安装 1.安装包下载:  http://www.sublimetext.com/3 (傻瓜式安装) 2.Package Control安装: 1)Ctrl+~或者View——Show Consol ...

  10. FFMpeg笔记(五) 录制小视频时几个问题解决

    1. YUV数据在使用avfilter scale时在特定的分辨率下UV分量不对 由于是小视频,那么分辨率不需要太高,但是有的视频源是1080p,甚至有的是4K的,所以对视频源进行scale非常有必要 ...