上位机通过CCD视觉识别条形码与二维码
上位机通过CCD视觉识别条形码与二维码
上位机通过CCD视觉识别条形码与二维码
上位机通过CCD视觉识别条形码与二维码
1.条形码又称条码、一维码,是将字符按照特定的规则转化成二进制后,描绘成一个宽度不等的多个黑条和空白,按照一定的编码规则排列的图形标识符。条形码应用相当广泛,生活中,超市购物最为常见。 条形码的编码规则五花八门,有数十种,各种都有它特有的空间里发挥作用,类型多达255以上。 程序可支持的条形码种类可扩展:GS1 DataBar Omnidirectional, GS1 DataBar Truncated, GS1 DataBar Stacked, GS1 DataBar Stacked Omnidirectional, GS1 DataBar Limited, GS1 DataBar Expanded, GS1 DataBar Expanded Stacked, GS1-128, Code 128, EAN-13 Add-On 5, EAN-13 Add-On 2, EAN-13, UPC-A Add-On 5, UPC-A Add-On 2, UPC-A, EAN-8 Add-On 5, EAN-8 Add-On 2, EAN-8, UPC-E Add-On 5, UPC-E Add-On 2, UPC-E, Code 93, Code 39, Codabar, 2/5 Interleaved, 2/5 Industrial
2.程序可支持的三维码种类可扩展: 'Aztec Code', 'Data Matrix ECC 200', 'GS1 Aztec Code', 'GS1 DataMatrix', 'GS1 QR Code', 'Micro QR Code', 'PDF417', 'QR Code' QRcode码是最常用的二维码之一,它是将文本通过一定的规则转化为二进制后,编码生成的一个正方形的图形,由于在设计时就加入了很多自我纠错的功能和重复序列,让二维码生成有很强的纠错能力,就算是缺少了部分图像,仍然能解码出完整的文字信息。
下面是例程中核心代码 - BOOL CCode::Read2DCode(HWND hWnd,CString &sCode,CString sPicName)
- {
- if(!IsWindow(hWnd))
- return false;
- HObject ho_Image, ho_SymbolXLDs;
- HTuple hv_WindowHandle, hv_DataCodeHandle, hv_ResultHandles;
- HTuple hv_DecodedDataStrings, hv_Message,hv_PicName=sPicName;
- ReadImage(&ho_Image,hv_PicName);
- if (HDevWindowStack::IsOpen())
- CloseWindow(HDevWindowStack::Pop());
- OpenWindowFitImage(ho_Image, 0, 0, -1, -1, &hv_WindowHandle,hWnd);
- if(!HDevWindowStack::IsOpen())
- return false;
- CreateDataCode2dModel("QR Code", HTuple(), HTuple(), &hv_DataCodeHandle);
- FindDataCode2d(ho_Image, &ho_SymbolXLDs, hv_DataCodeHandle, HTuple(), HTuple(), &hv_ResultHandles, &hv_DecodedDataStrings);
- SetLineWidth(HDevWindowStack::GetActive(),3);
- SetColor(HDevWindowStack::GetActive(),"green");
- DispObj(ho_Image, HDevWindowStack::GetActive());
- DispObj(ho_SymbolXLDs, HDevWindowStack::GetActive());
- DisplayMsg(hv_WindowHandle, hv_DecodedDataStrings, "window", 40, 12, "black", "true");
- hv_Message = "No data code found.";
- hv_Message[1] = "The symbol could not be found with the standard";
- hv_Message[2] = "default setting. Please adjust the model parameters to read this symbol.";
- if(hv_DecodedDataStrings.TupleLength()==0)
- {
- DisplayMsg(hv_WindowHandle, hv_Message, "window", 40, 12, "red", "true");
- return false;
- }
- ClearDataCode2dModel(hv_DataCodeHandle);
- sCode = hv_DecodedDataStrings.S();
- return true;
- }
复制代码- BOOL CCode::ReadBarCode(HWND hWnd,CString &sCode,CString sPicName)
- {
- if(!IsWindow(hWnd))
- return false;
- HObject ho_Image, ho_SymbolRegions;
- HTuple hv_BarCodeHandle, hv_WindowHandle, hv_DecodedDataStrings,hv_Width, hv_Height,hv_PicName=sPicName;
- CreateBarCodeModel(HTuple(), HTuple(), &hv_BarCodeHandle);
- SetBarCodeParam(hv_BarCodeHandle, "stop_after_result_num", 1);
- SetWindowAttr("background_color","black");
- ReadImage(&ho_Image, hv_PicName);
- GetImageSize(ho_Image, &hv_Width, &hv_Height);
- if (HDevWindowStack::IsOpen())
- CloseWindow(HDevWindowStack::Pop());
- OpenWindowFitImage(ho_Image, 0, 0, -1, -1, &hv_WindowHandle,hWnd);
- HDevWindowStack::Push(hv_WindowHandle);
- if (!HDevWindowStack::IsOpen())
- return false;
- SetBarCodeParam(hv_BarCodeHandle, "check_char", "absent");
- FindBarCode(ho_Image, &ho_SymbolRegions, hv_BarCodeHandle, "2/5 Industrial", &hv_DecodedDataStrings);
- SetBarCodeParam(hv_BarCodeHandle, "check_char", "present");
- FindBarCode(ho_Image, &ho_SymbolRegions, hv_BarCodeHandle, "2/5 Industrial", &hv_DecodedDataStrings);
- DisplayMsg(hv_WindowHandle, hv_DecodedDataStrings, "window", 36, 12, "black", "false");
- SetColor(HDevWindowStack::GetActive(),"magenta");
- SetDraw(HDevWindowStack::GetActive(),"margin");
- SetLineWidth(HDevWindowStack::GetActive(),3);
- DispObj(ho_Image, hv_WindowHandle);
- DispObj(ho_SymbolRegions, hv_WindowHandle);
- ClearBarCodeModel(hv_BarCodeHandle);
- sCode = hv_DecodedDataStrings.S();
- return true;
- }
复制代码- void CBarCodeView::OnButton1()
- {
- static int Index=0;
- Index++;
- if(Index>4)
- Index=1;
- CString sCode,sPicName;
- sPicName.Format("pic/25industrial0%d.png",Index);//::MessageBox(NULL,sPicName,"",NULL);
- m_Code.ReadBarCode(GetDlgItem(IDC_BARCODE)->m_hWnd,sCode,sPicName);
- SetDlgItemText(IDC_EDIT1,sCode);
-
- CRect rc;
- GetClientRect(rc);
- InvalidateRect(&rc);
- }
- void CBarCodeView::OnButton3()
- {
- static int Index=0;
- Index++;
- if(Index>10)
- Index=1;
- CString sCode,sPicName;
- sPicName.Format("pic/qr_workpiece_%0.2d.png",Index);
- m_Code.Read2DCode(GetDlgItem(IDC_BARCODE)->m_hWnd,sCode,sPicName);
- SetDlgItemText(IDC_EDIT1,sCode);
- }
复制代码百度云附件:上位机通过CCD视觉识别条形码与二维码.rar 如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|