標籤:
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
DM二維碼識別庫DMDECODER的使用--MFC常式