Two-dimensional code data Matrix simple Introduction and 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-based, dark-colored square module, with each square module being a basic unit. Each basic unit is encoded into one bit of data.

The data area is surrounded by probing graphs. Used for barcode symbol positioning and determining barcode structure information. The perimeter of the probe is a blank area that separates the barcode symbol from the background.

The probe graph is the width of a module. is the boundary of the data area, in which all two adjacent edges composed of dark modules constitute an "L"-shaped solid line edge, "L" opposite the alternating depth of the two adjacent edge of the module formed by the edge of the line. The exploration graph is mainly used to define the unit structure of the symbol, and can also be used to determine the physical dimensions of the symbol. and 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. Encode data in binary code mode. So the computer can read directly. The Dark module represents "1". The light-colored module represents "0", then uses a series of specific arrangement of the depth of the module to describe the descriptive code word information, and then arranged into a matrix symbol, and finally form the data matrix barcode.

So. Random data matrix symbols can be composed of four parts: Probe into the shape of the "L" shape of the two solid line edge, probe the graph in the shape of the "L" shape opposite the two dashed edge, the data area surrounded by the measured graph, bar code symbol around the width of a module blank space.

Data Matrix Barcode Coding is the conversion of item information into a data stream, using two-dimensional barcode symbol to express the implementation.

Agree to various input data information. Can be numbers and letters, can be regular text, character information, but also can be multimedia information, such as sound, pictures, fingerprints 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 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). Sizes from 9*9 to 49*49. The upper-right corner of the ECC 200 symbol is a light module (even). Dimensions from 10*10 to 144*144, if rectangular, 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 best encoding rules into data code words. Second, according to the Reed-solomon algorithm and the response of the error correction requirements, the data code word based on the generation of error-correcting code word, data code word plus error correction code word and may need some of the fill characters, constitute the coded word stream; Thirdly, the module will be placed in the matrix according to the standard template, and the probe graph will be added. Generates the data matrix two-dimensional matrix code symbol.

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

Data Matrix Barcode Image preprocessing: First of all, the color image is grayscale, then the gray image is filtered and de-noising, the appropriate threshold is selected for the image binary, and the edge is finally extracted.

Barcode positioning: Area initial positioning, edge detection, rotation correction, accurate extraction, barcode cutting (grid).

Data matrix Barcode Decoding and recognition: according to the sample mesh, the depth module is converted to "1", "0" Matrix. Remove the detection graph, extract the data area, and get the barcode size and version number information, call the module placement matrix to restore the correct sequence of code stream. Then determine the data code Word and Error correction code word, and the barcode data error correction. Finally, the original data is restored and the output is decoded correctly.

Data Matrix Core Library Its license is BSD, the specific 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 number libdmtx-0.7.4 from http://sourceforge.net/projects/libdmtx/;

2. Create a new LIBDMTX static library project to add the corresponding. h,. c files under the/libdmtx-0.7.4 folder to this project;

3. Adjust the source code: (1), the dmtx.h and dmtxstatic.h two header files are included in each. c file, (2), in the case of error C2129, the way to deal with the Declaration and implementation of the "static" keyword are removed; (3), Add Float.h, Stdio.h, Limits.h, assert.h, math.h files to Dmtx.h, (4), Chkerr, Chkscheme, Chksize, Callback_ The definitions of matrix etc. are copied from dmtxencodescheme.c to Dmtx.h, (5), the. c files included in the Dmtx.c file, and (6) the snprintf function in the file is replaced with the sprintf_s function;

4. Create a new Barcodetest console project to make a simple test of the LIBDMTX library. The relevant file code such as the following (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;}

GitHub: Https://github.com/fengbingchun/BarCode_Test

Two-dimensional code data Matrix simple Introduction and 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.