文章目录

  • 前言
  • 一、Data Matrix 的加密
    • 1.DM码的数据编码格式
    • 2.DM码原始数据编码方法
    • 3.DM码的大小和容量
    • 4.DM码填充字的生成方法
    • 5.校验码的生成方法
    • 6.DM码的布置
  • 二、相关开源算法
  • 总结

前言

Data Matrix是一种二维码标签,可以用来储存信息,简称DM码。

本文记录学习Data Matrix的解码及加密,本文主要针对ECC200标准。


一、Data Matrix 的加密

1.DM码的数据编码格式

|Data codewords|Stuffing codewords| Correction codewords|

Data codewords: 从原始数据编码得到的数据字
Stuffing codewords:如果数据字区域没有填满,用来填充的字
Correction codewords: 基于数据字和填充字,用 Reed-Solomon算法来校验产生的校验字.

2.DM码原始数据编码方法



默认采用ASCLL编码方式。
数据按照以下三种可能进行编码
o 如果数据不是扩展的ASCLL码(0到127),直接将其ASCLL码加1
o 如果数据是扩展的ASCLL码(128到255),通常是转换为两个字,第一个字是235,第二个字是其ASCLL码减127。
o 如果数据是数字,每两个数字组成一个编码,将这两个数字的值加上130。

3.DM码的大小和容量

以下是DM码的大小和容量信息,可以看出数据区大小为8x8的DM码只能容纳3个byte的数据码和5个byte的校验码。

4.DM码填充字的生成方法

当数据字不足以填充所有的数据区域时,可以采用填充字。填充字的第一个字总是129,后面的字可以用以下公式获取。

o "%"代表求模,i代表第i个位置的数据

5.校验码的生成方法

相关C代码如下

/* "prod(x,y,log,alog,gf)" returns the product "x" times "y" */
int prod(int x, int y, int *log, int *alog, int gf) {
if (!x || !y) return 0;
ELSE return alog[(log[x] + log[y]) % (gf-1)];
}
/* "ReedSolomon(wd,nd,nc,gf.pp)" takes "nd" data codeword values in wd[] */
/* and adds on "nc" check codewords, all within GF(gf) where "gf" is a */
/* power of 2 and "pp" is the value of its prime modulus polynomial */
void ReedSolomon(int *wd, int nd, int nc, int gf, int pp) {
int i, j, k. *log,*alog,*c;
/* allocate, then generate the log & antilog arrays: */
log = malloc(sizeof(int) * gf);
alog = malloc(sizeof(int) * gf);
log[0] = 1-gf; alog[0] = 1;
for (i = 1; i < gf; i++) {
alog[i] = alog[i-1] * 2;
if (alog[i] >= gf) alog[i] ^= pp;
log[alog[i]] = i;
}
/* allocate, then generate the generator polynomial coefficients: */
c = malloc(sizeof(int) * (nc+1));
for (i=1; i<=nc; i++) c[i] = 0; c[0] = 1;
for (i=1; i<=nc; i++) {
c[i] = c[i-1];
for (j=i-1; j>=1; j--) {
c[j] = c[j-1] ^ prod(c[j],alog[i],log,alog,gf);
}
c[0] = prod(c[0],alog[i],log,alog,gf);
}
/* clear, then generate "nc" checkwords in the array wd[] : */
for (i=nd; i<=(nd+nc); i++) wd[i] = 0;
for (i=0; i<nd; i++) {
k = wd[nd] ^ wd[i] ;
for (j=0; j<nc; j++) {
wd[nd+j] = wd[nd+j+l] ^ prod(k,c[nc-j-1],log, alog,gf);
}
}
free(c);
free(alog);
free(log);
}

6.DM码的布置

根据你的数据大小,参考标准DataMatrix国际标准ISO16022-2006进行布置。


相关布置算法如下

#include <stdio.h>
#include <alloc.h>
int nrow, ncol, *array;
/* "module" places "chr+bit" with appropriate wrapping within array[] */
void module(int row, int col, int chr, int bit)
{ if (row < 0) { row += nrow; col += 4 - ((nrow+4)%8); }
if (col < 0) { col += ncol; row += 4 - ((ncol+4)%8); }
array[row*ncol+col] = 10*chr + bit;
}
/* "utah" places the 8 bits of a utah-shaped symbol character in ECC200 */
void utah(int row, int col, int chr)
{ module(row-2,col-2,chr,1);
module(row-2,col-1,chr,2);
module(row-1,col-2,chr,3);
module(row-1,col-1,chr,4);
module(row-1,col,chr,5);
module(row,col-2,chr,6);
module(row,col-1,chr,7);
module(row,col,chr,8);
}
/* "cornerN" places 8 bits of the four special corner cases in ECC200 */
void corner1(int chr)
{ module(nrow-1,0,chr,1);
module(nrow-1,1,chr,2);
module(nrow-1,2,chr,3);
module(0,ncol-2,chr,4);
module(0,ncol-1,chr,5);
module(1,ncol-1,chr,6);
module(2,ncol-1,chr,7);
module(3,ncol-1,chr,8);
}
void corner2(int chr)
{ module(nrow-3,0,chr,1);
module(nrow-2,0,chr,2);
module(nrow-1,0,chr,3);
module(0,ncol-4,chr,4);
module(0,ncol-3,chr,5);
module(0,ncol-2,chr,6);
module(0,ncol-1,chr,7);
module(1,ncol-1,chr,8);
}
void corner3(int chr)
{ module(nrow-3,0,chr,1);
module(nrow-2,0,chr,2);
module(nrow-1,0,chr,3);
module(0,ncol-2,chr,4);
module(0,ncol-1,chr,5);
module(1,ncol-1,chr,6);
module(2,ncol-1,chr,7);
module(3,ncol-1,chr,8);
}
void corner4(int chr)
{ module(nrow-1,0,chr,1);
module(nrow-1,ncol-1,chr,2);
module(0,ncol-3,chr,3);
module(0,ncol-2,chr,4);
module(0,ncol-1,chr,5);
module(1,ncol-3,chr,6);
module(1,ncol-2,chr,7);
module(1,ncol-1,chr,8);
}
/* "ECC200" fills an nrow x ncol array with appropriate values for ECC200 */
void ECC200(void)
{ int row, col, chr;
/* First, fill the array[] with invalid entries */
for (row=0; row<nrow; row++) {
for (col=0; col<ncol; col++) {
array[row*ncol+col] = 0;
}
}
/* Starting in the correct location for character #1, bit 8,... */
chr = 1; row = 4; col = 0;
do {
/* repeatedly first check for one of the special corner cases, then... */
if ((row == nrow) && (col == 0)) corner1(chr++);
if ((row == nrow-2) && (col == 0) && (ncol%4)) corner2(chr++);
if ((row == nrow-2) && (col == 0) && (ncol%8 == 4)) corner3(chr++);
if ((row == nrow+4) && (col == 2) && (!(ncol%8))) corner4(chr++);
/* sweep upward diagonally, inserting successive characters,... */
do {
if ((row < nrow) && (col >= 0) && (!array[row*ncol+col]))
utah(row,col,chr++);
row -= 2; col += 2;
} while ((row >= 0) && (col < ncol));
row += 1; col += 3;
/* & then sweep downward diagonally, inserting successive characters,... */
+
do {
if ((row >= 0) && (col < ncol) && (!array[row*ncol+col]))
utah(row,col,chr++);
row += 2; col -= 2;
} while ((row < nrow) && (col >= 0));
row += 3; col += 1;
/* ... until the entire array is scanned */
} while ((row < nrow) || (col < ncol));
/* Lastly, if the lower righthand corner is untouched, fill in fixed pattern */
if (!array[nrow*ncol-1]) {
array[nrow*ncol-1] = array[nrow*ncol-ncol-2] = 1;
}
}
/* "main" checks for valid command line entries, then computes & displays array
*/
void main(int argc, char *argv[])
{ int x, y, z;
if (argc =< 3) {
printf("Command line: ECC200 #_of_Data_Rows #_of_Data_Columns\n");
} ELSE {
nrow = ncol = 0;
nrow = atoi(argv[1]); ncol = atoi(argv[2]);
if ((nrow >= 6) && (~nrow&0x01) && (ncol >= 6) && (~ncol&0x01)) {
array = malloc(sizeof(int) * nrow * ncol);
ECC200();
for (x=0; x<nrow; x++) {
for (y=0; y<ncol; y++) {
z = array[x*ncol+y];
if (z == 0) printf(" WHI");
ELSE if (z == 1) printf("BLK");
ELSE printf("%3d.%d",z/10,z%10);
}
printf("\n");
}
free(array);
}
}
}

二、相关开源算法

libdmtx - Open Source Data Matrix Software under a Simplified BSD license with an alternate
waiver option, The non-library components related to libdmtx are distributed under a different license(typically LGPLv2)
DataMatrix reading and writing library, utils and wrappers · GitHub
huBarcode- huBarcode is a Python Library to generate 1D and 2D Barcodes. Open source, BSD,GPL or Apache Licensed.
GitHub - hudora/huBarcode: huBarcode is a Python Library to generate 1D and 2D Barcodes
ZXing- is/was a Java library. the C++ port is no longer maintained and has been removed from the official ZXing repo.
GitHub - glassechidna/zxing-cpp: ZXing C++ Library


总结

本文总结了DM 码基于ECC200标准的编码原理,以及编码解码的相关开源代码。

关于Data Matrix 基于ECC200标准的编码原理和相关开源代码相关推荐

  1. 基于遥感影像的道路提取论文、开源代码和数据集汇总

    文章目录 前言 2017 DeepRoadMapper Topology Loss 2018 RoadTracer iterative-deep-learning 2019 Leveraging Cr ...

  2. JPEG编码原理及文件格式及代码分析

    一 JPEG编码原理 首先我们先来看一下JPEG的编码原理图 如上图所示,下面进行逐步的分析: 1 RGB->YUV 首先为了降低互相的关联性,将RGB转换为YUV,这样就可以对亮度信号和色度信 ...

  3. 哈夫曼编码原理与Python实现代码(附手动推导过程原稿真迹)

    哈夫曼编码依据字符出现概率来构造异字头(任何一个字符的编码都不是其他字符的前缀)的平均长度最短的码字,通过构造二叉树来实现,出现频次越多的字符编码越短,出现频次越少的字符编码越长.为了演示哈夫曼编码原 ...

  4. 一些基于深度学习的视觉里程计/SLAM开源代码

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者:黄浴 https://zhuanlan.zhihu.com/p/139150194 本文转载自知 ...

  5. Huffman 编码原理详解(代码示例)

    1.概述 huffman编码是一种可变长编码(  VLC:variable length coding))方式,于1952年由huffman提出.依据字符在需要编码文件中出现的概率提供对字符的唯一编码 ...

  6. 最新汇总:一些基于深度学习的视觉里程计/SLAM开源代码

    点上方蓝字计算机视觉联盟获取更多干货 在右上方 ··· 设为星标 ★,与你不见不散 仅作分享,不代表本公众号立场,侵权联系删除 转载于:黄浴博士知乎,已获授权,https://zhuanlan.zhi ...

  7. 基于ROS的Most Stars开源代码汇总(自动驾驶汽车+RGBDSLAMv2+ROS2+人识别与跟踪等)

    Star 200+ https://github.com/CPFL/Autoware 用于城市自主驾驶的开源软件. http://www.tier4.jp/ Autoware 用于城市自主驾驶的集成开 ...

  8. JPEG编码原理及简易编码器实现

    简介 以学习为目的编写的简易jpeg编码器,以看得懂为目标,代码尽可能清晰简洁,不对内存.性能做看不懂的优化,也不实现jpeg更多高级特性. 这篇文章是我从自己的开源工程中整理来的 本文对应的工程为h ...

  9. 基于机器视觉的Data Matrix二维码识别

    基于机器视觉的Data Matrix二维码识别 二维码识别,这个在视觉应用中占有很重要的比例,各种各样的二维码都有可能需要识别.常见的QR码.Data Matrix码.本方案是识别Data Matri ...

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

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

最新文章

  1. 1.2操作系统的特征
  2. Java UDP协议传输
  3. leetcode 140. Word Break II | 140. 单词拆分 II(动态规划)
  4. 搭建一个高可用的镜像仓库,这是我见过最详细、最简单的教程
  5. 练习ddt-file_data时,报错UnboundLocalError local variable ‘value‘ referenced before assignment
  6. net 架构师-数据库-sql server-003-T-SQL 基本语句
  7. 技术实践丨PostgreSQL开启Huge Page场景分析
  8. 阿里依然在“飙车”!第一财季净利润309.49亿元 同比增长54%
  9. TensorFlow精进之路(七):关于两层卷积神经网络对CIFAR-10图像的识别
  10. 【渝粤教育】国家开放大学2019年春季 2718动物生理基础 参考试题
  11. linux怎样安装麒麟双系统,U盘启动中标麒麟V6双系统安装教程
  12. cors nginx 怎么解决_如何在Nginx代理服务器中启用CORS?
  13. CodeForces-1040B Shashlik Cooking(贪心)
  14. HTML META 元数据标签详解
  15. amap和amapcrap使用
  16. 两个椭圆的公切线求法(Matlab)
  17. JavaFX之Scene Builder的使用(开发一款GUI小工具原来这么简单)
  18. linux无线鼠标右键自动选择,2020年高性价比无线鼠标推荐
  19. Codeforces - 1166E - The LCMs Must be Large
  20. 什么是视觉动力 ​——工业设计与视觉动力

热门文章

  1. fai 安装debian
  2. 阿里安全研究员路全:如何运用AI对抗“数据污染”?
  3. 深入理解操作系统实验——bomb lab(phase_3)
  4. php 正则 问号,正则表达式的问号需要怎样使用
  5. Au 效果器详解:自适应降噪
  6. 【ZYNQ】petalinux包含自定义的动态库
  7. 1.1微信支付之现金红包 - Java 开发
  8. 领导者激励团队的最佳方法
  9. 沟通的艺术与处世智慧 ——戴尔卡耐基(笔记)
  10. CF407C Curious Array