Introduction of QR code Data matrix and its compilation in VS2010

Source: Internet
Author: User

The data matrix two-dimensional barcode, formerly known as Datacode, was invented in 1989 by the United States International Information Corporation (International data Matrix, referred to as ID matrix). Data-matrix Two-dimensional barcode is a matrix-type two-dimensional barcode.

The data matrix symbol consists of a rule-arranged, dark-colored square module, each of which is a basic unit, each of which is encoded as one bit of data. The data area is surrounded by probing graphics, which are used for barcode symbol positioning and for determining barcode structure information. The perimeter of the probe graph is a blank area that separates the barcode symbol from the background.

The probe graph is the width of a module, which is the boundary of the data area, in which all two adjacent edges composed of dark modules constitute an "L"-shaped solid line edge, and the "L" opposite by alternating shading module of two adjacent edges constitute a dashed edge. Probing graphics are mainly used to define the unit structure of symbols, and can also be used to determine the physical dimensions of symbols, as well as to solve problems such as symbol positioning and distortion.

The data area is a square area composed of several square-depth modules, and the information is stored in different arrangement combinations of the depth modules. The data is encoded in binary code mode, so the computer can read directly. The Dark module represents "1", the light-colored module represents "0", and then uses a series of specific arrangement of the depth of the module to describe the code word information, and then arranged into a matrix symbol, the final form of data matrix barcode.

Therefore, the arbitrary data matrix symbol can be composed of four parts: probing the graph "L" shape two solid line edge, probing the graph in the "L" shape opposite the two dashed edge, the data area surrounded by the probe graph, bar code symbol around the width of a module blank area.

Data Matrix Barcode Coding is the conversion of item information into a data stream, using two-dimensional barcode symbol to express the implementation. Allows the input data information is diverse, may be the number and the letter, may be the general text, the character information, may also be the multimedia information, such as the sound, the picture, the fingerprint and so on.

Data matrix is divided into ECC 000-140 and ECC 2002 Large class, ECC 000-140 has four levels of convolution error correction function, ECC 200 through the Reed-solomon error correction algorithm to calculate error correction code, according to the different sizes of the symbols to get different error correction code. The appearance difference between the two types of symbols is that the upper-right corner of the ECC 000-140 symbol is a dark-colored module (odd only) and the size is from 9*9 to 49*49. The upper-right corner of the ECC 200 symbol is a light module (even), with dimensions from 10*10 to 144*144, and rectangles from 8*18 to 16*48. ECC 200 is used more.

The data matrix code consists of three parts: one is to convert the information flow through the optimal coding rules into data code word, and the other is to generate error-correcting code word based on the data code word, data code word plus error correcting code word and some padding characters which may be needed according to the Reed-solomon algorithm and the error correction request of the response. , which constitute the coded word stream; Thirdly, the module will be placed into the matrix according to the standard template, and the detection graph will be added to generate the data matrix two-dimensional matrix code symbol.

Data Matrix Two-dimensional barcode image recognition mainly includes image preprocessing, barcode positioning, sampling and decoding.

Data Matrix Barcode Image preprocessing: firstly, the color image is grayscale, then the gray image is filtered and de-noising, the appropriate threshold value is selected for the image binary, and the edge is extracted at last.

Barcode positioning: Area initial positioning, edge detection, rotation correction, accurate extraction, bar code segmentation (GRID).

Data matrix barcode decoding and recognition: According to the sampling grid, the depth module is converted to "1", "0" matrix, remove the detection graph, extract the data area, and get the barcode size and version information, call the module placement matrix to restore the correct sequence of code word flow, and then determine the data code Word and Error correction code word, The error correction of barcode data is done and the original data is restored, and the output is decoded correctly.

Data Matrix Core Library Its license is BSD, detailed introduction see homepage http://www.libdmtx.org/.

The following is a detailed description of the data matrix compilation process in VS2010:

1. Download its stable version libdmtx-0.7.4 from http://sourceforge.net/projects/libdmtx/;

2. Create a new LIBDMTX static library project and add the corresponding. h,. c files in the/libdmtx-0.7.4 directory to the project;

3. The source code is adjusted: (1), the dmtx.h and dmtxstatic.h two header files are included in each. c file, (2), for error C2129, the method is to remove the "static" keyword in the Declaration and implementation; (3), Float.h, Stdio.h, Limits.h, assert.h, math.h files are added to the Dmtx.h, (4), Chkerr, Chkscheme, Chksize, Callback_ The definition of matrix and so on is copied from dmtxencodescheme.c to Dmtx.h, (5), comment out the. c file contained in the Dmtx.c file, (6), replace the snprintf function in the file with the sprintf_s function;

4. New Barcodetest Console project, the LIBDMTX library for a simple test, the relevant file code is as follows (code reference/LIBDMTX-0.7.4/TEST/SIMPLE-TEST/SIMPLE_TEST.C):

StdAfx.h:

#pragma once#include "targetver.h" #include <stdio.h> #include ". /.. /src/datamatrix/libdmtx-0.7.4/dmtx.h "

Stdafx.cpp:

#include "stdafx.h" #ifdef _debug#pragma comment (lib, "... /.. /.. /lib/dbg/x86_vc10/libdmtx[dbg_x86_vc10].lib ") #else #pragma comment (lib," ... /.. /.. /lib/rel/x86_vc10/libdmtx[rel_x86_vc10].lib ") #endif

Barcodetest.cpp:

#include "stdafx.h" #include <iostream> #include <assert.h> #include <string>using namespace Std;int Main (int argc, char* argv[]) {size_t width, height, bytesperpixel;string str = "China [email protected]#$! "; string dst;unsigned char *pxl;dmtxencode *enc;dmtximage *img;dmtxdecode *dec;dmtxregion *reg;dmtxmessa GE *msg;//fprintf (stdout, "Input: \"%s\ "\ n", str);cout<< "str:" <<str<<endl;/* 1) ENCODE a new Data Matrix barcode Image (in memory only) */enc = Dmtxencodecreate (); assert (enc! = NULL);//dmtxencodedatamatrix (Enc, strlen (s TR), str);d Mtxencodedatamatrix (Enc, strlen (Str.c_str ()), (unsigned char*) str.c_str ());/* 2) COPY The new image data befor E releasing encoding memory */width = Dmtximagegetprop (Enc->image, dmtxpropwidth); height = Dmtximagegetprop (enc-> Image, dmtxpropheight); bytesperpixel = Dmtximagegetprop (Enc->image, dmtxpropbytesperpixel);p XL = (unsigned char *) malloc (Width * height * bytesperpixel); ASSERT (PXL! = NULL); memcpy (PXL, enc->image->pxl, Width * height * bytesperpixel);d Mtxencodedestroy (&AMP;ENC);/* 3) DECODE T He Data Matrix barcode from the copied image */img = Dmtximagecreate (pxl, width, height, dmtxpack24bpprgb); Assert (img! = N ULL);d EC = Dmtxdecodecreate (IMG, 1); assert (dec! = null); reg = Dmtxregionfindnext (dec, null); if (reg! = null) {msg = Dmtxdec Odematrixregion (Dec, Reg, dmtxundefined), if (msg! = NULL) {/*fputs ("Output: \" ", stdout); fwrite (Msg->output, sizeof ( unsigned char), MSG-&GT;OUTPUTIDX, stdout) fputs ("\" \ n ", stdout); */dst = string (Reinterpret_cast<const char*> ( msg->output));d Mtxmessagedestroy (&msg);} Dmtxregiondestroy (&reg);} cout<< "DST:" <<dst<<endl;dmtxdecodedestroy (&AMP;DEC);d Mtximagedestroy (&img); free (PXL); cout<< "ok!" <<endl;return 0;}


Introduction of QR code Data matrix and its compilation in VS2010

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.