DM二維碼識別庫DMDECODER的使用--MFC例程


    DM碼和QR碼是當今比較主流的二維碼,其中QR碼容量大,容量密度為16kb,DM碼容量要小一點,可在僅僅25mm²的面積上編碼30個數字,但是DM碼的容錯率更高,所以實際的工業生產中經常使用DM碼作為產品的標簽。

    DMDECODER是一款比較好用的DM碼解析軟件,包含有一個DLL和一個lib,使用這個庫也比較容易我們先看組成

    

使用該庫第一步是導入庫路徑和庫函數如下

//導入dll
#define DLL_EXPORT __declspec(dllexport)  

extern "C" DLL_EXPORT int _stdcall DataMatrix_decode(const char* filename); 
//    DataMatrix_decode_rt --> 對設備采集的圖像進行實時處理
//    imageData   : 指向圖像數據區的指針(24位位圖)
//    width       : 圖像寬度
//    height      : 圖像高度
extern "C" DLL_EXPORT int _stdcall DataMatrix_decode_rt(unsigned char* imageData, int width, int height); 
extern "C" DLL_EXPORT int _stdcall DataMatrix_output(unsigned char* message); 

然后解碼過程是這樣的

char* file = (char*)malloc(sourceFilePath.GetLength()+1);//待解碼圖片路徑
        for(int i = 0; i < sourceFilePath.GetLength();i++)
        {
            file[i] = sourceFilePath.GetAt(i);
        }
        file[sourceFilePath.GetLength()] = 0;
        int length = DataMatrix_decode(file); //解碼並返回碼字長度(解碼失敗則返回-1)
        if(length>0)
        {
            unsigned char* message = (unsigned char*)malloc(sizeof(char)*(length+1));
            DataMatrix_output(message);//將解碼碼字保存到數組中
            message[length] = 0;
            convertString.Empty();
            convertString.AppendFormat("%s",message);
            CString show;
            show.Empty();
            show = convertString.Left(convertString.GetLength()-12);
            ((CEdit*)GetDlgItem(IDC_EDIT_COVERT_RESULT))->SetWindowText(show);
            free(message);
        }    

完整的MFC工程如下

注意結果尾巴上的版權標志tonxong.com去掉哦

工程路徑

http://download.csdn.net/detail/dengrengong/8608187

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM