DataMatrix identification and location project notes -- DataMatrix generator based on QT+libdmtx-0.7.5

Keywords: Qt github encoding C

The project of generating DataMatrix based on qt and libdmtx,

DataMatrix open source coding and identification Library: github of libdmtx: https://github.com/dmtx/libdmtx

The complete project I wrote in qt is: https://github.com/abcvincent/dmtxMaker

GitHub - > doc contains DataMatrix international standard files and Zhihu's detailed QR code documents;

The effect is as follows:

The following is a simple test code, qt project:

//Test code
//    QString str = "DataMatrix";
QString str = "123456789";
DmtxEncode* encode = dmtxEncodeCreate();
assert(encode != NULL);
encode->moduleSize = 5;
encode->marginSize = 5;
encode->sizeIdxRequest=DmtxSymbolSquareAuto;//Set type default

//    dmtxEncodeSetProp( encode, DmtxPropModuleSize, 5); // encode->moduleSize = 5;
//    dmtxEncodeSetProp( encode, DmtxPropMarginSize,20); //  encode->marginSize = 10;

//    The following is the default function setting in the code dmtxencode. C - > dmtxencodecreate (void);
//    encode->scheme = DmtxSchemeAscii;
//    encode->sizeIdxRequest = DmtxSymbolSquareAuto;
//    encode->marginSize = 10;
//    encode->moduleSize = 5;
//    encode->pixelPacking = DmtxPack24bppRGB;
//    encode->imageFlip = DmtxFlipNone;
//    encode->rowPadBytes = 0;
//    encode->fnc1 = DmtxUndefined;

//    int ret = dmtxEncodeDataMatrix(encode, strlen(str.toStdString().c_str()), (unsigned char*)str.toStdString().c_str()); / / case function c language
int ret = dmtxEncodeDataMatrix(encode, str.size(), (uchar*)str.toStdString().data());
assert(ret == 1);

int width = dmtxImageGetProp(encode->image, DmtxPropWidth);
int height = dmtxImageGetProp(encode->image, DmtxPropHeight);
int bytesPerPixel = dmtxImageGetProp(encode->image, DmtxPropBytesPerPixel);
int bytesPerLine = dmtxImageGetProp(encode->image, DmtxPropRowSizeBytes);

uchar *pxlData = (uchar *)malloc(width*height*bytesPerPixel);
memcpy(pxlData,encode->image->pxl,width*height*bytesPerPixel);
dmtxEncodeDestroy(&encode);

QImage img = QImage(pxlData,width,height,bytesPerLine,QImage::Format_RGB888);//If RGB888 can't change to another format
QImage imgshow=img.scaled( this->ui->label->width(), this->ui->label->height(),Qt:: KeepAspectRatio);
ui->label->setPixmap(QPixmap::fromImage(imgshow));

The following is an example of test in libdmtx library, pure c code, portable embedded, output data values of 0 and 1, each representing a pixel;

    //libdmtx comes with example
    size_t          width, height, bytesPerPixel;
    unsigned char   str[] = "30Q324343430794<OQQ";
    unsigned char  *pxl;
    DmtxEncode     *enc;
    DmtxImage      *img;
    DmtxDecode     *dec;
    DmtxRegion     *reg;
    DmtxMessage    *msg;

    //1) ENCODE a new Data Matrix barcode image (in memory only)
    enc = dmtxEncodeCreate();
    //dmtxEncodeSetProp( enc, DmtxPropPixelPacking, DmtxPack16bppRGB );
    //dmtxEncodeSetProp( enc, DmtxPropPixelPacking, DmtxPack32bppRGB );
    //dmtxEncodeSetProp( enc, DmtxPropWidth, 160 );
    //dmtxEncodeSetProp( enc, DmtxPropHeight, 160 );

    assert(enc != NULL);
    dmtxEncodeDataMatrix(enc, strlen((const char *)str), str);
    //2) COPY the new image data before releasing encoding memory
    width = dmtxImageGetProp(enc->image, DmtxPropWidth);
    height = dmtxImageGetProp(enc->image, DmtxPropHeight);
    bytesPerPixel = dmtxImageGetProp(enc->image, DmtxPropBytesPerPixel);
    pxl = (unsigned char *)malloc(width * height * bytesPerPixel);//Functions of malloc c
    assert(pxl != NULL);
    memcpy(pxl, enc->image->pxl, width * height * bytesPerPixel);

    //    int width = dmtxImageGetProp(enc->image, DmtxPropWidth);
    //    int height = dmtxImageGetProp(enc->image, DmtxPropHeight);
    //    int bytesPerPixel = dmtxImageGetProp(enc->image, DmtxPropBytesPerPixel);
    int bytesPerLine = dmtxImageGetProp(enc->image, DmtxPropRowSizeBytes);
    dmtxEncodeDestroy(&enc);//Clear memory
    fprintf(stdout, "width:  \"%d\"\n", width);
    fprintf(stdout, "height: \"%d\"\n", height);
    fprintf(stdout, "bpp:    \"%d\"\n", bytesPerPixel);

    for (int i=0; i<width*height; i++){
       fprintf(stdout, "%d", (pxl[i*3])==0);
       if (i%width==width-1){
          fprintf(stdout, "\n");

 

79 original articles published, 90 praised, 260000 visitors+
Private letter follow

Posted by BSTRhino on Sat, 01 Feb 2020 07:08:39 -0800