Halcon识别一维码的代码实例

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

StageI'shdev的代码实例===============================================================================*AutodiscriminationA.hdev**CodegeneratedbyImageAcquisition03*获取条形码,并计算及显示解码时间,并从规定读取的条码类型范围中读取被解码的条码类型也可设置成不规定条码类型即自动识别,但会增加解码时间,甚至出现误读的情况。*可读取多个不同类型的条码,并且多个条码用不同颜色的区域框区分,且读取出来的信息也以相应的颜色做区分dev_close_window()dev_open_window(0,0,600,600,'black',WindowHandle)*先关闭活动图形窗口,再打开这个窗口,标识符为WindowHandle;*相对于界面左上角第0行、第0列,大小为300×300像素,颜色为黑色。open_framegrabber('DirectShow',1,1,0,0,0,0,'default',8,'rgb',-1,'false','default','GsouUSB2.0Camera',0,-1,AcqHandle)*打开帧接收器(图像采集设备,如摄像头,工业相机等),参数(Parameter)详见这个算子注意,采集器名称不同要更改,或者用助手获取也可以。grab_image_start(AcqHandle,-1)while(true)grab_image_async(Image,AcqHandle,-1)*开始条形码识别create_bar_code_model([],[],BarCodeHandle)*必备的创建条码解码的开头,下面有一段结束代码dev_update_var('off')dev_update_pc('off')dev_update_window('off')*刷新窗体set_display_font(WindowHandle,14,'mono','true','false')dev_set_draw('margin')dev_set_line_width(3)Colors:=['forestgreen','magenta','blue','red','yellow']*设置区域框的属性,如无填充色、边框线大小为3,颜色。*CodeTypes:=['auto']CodeTypes:=['EAN-13','Code39','EAN-8','Code128','Code93']*设置条码的类型,如EAN-13等5种一维码类型,或者auto自动获取(但解码时间较长且有误读的可能)get_image_size(Image,Width,Height)dev_display(Image)*获取图像大小,并显示图像count_seconds(Start)find_bar_code(Image,SymbolRegions,BarCodeHandle,CodeTypes,DecodedDataStrings)count_seconds(Stop)Duration:=(Stop-Start)*1000*开始计时、寻找并解码条形码(参数解释详见这个算子),结束计时,并计算解码的时间dev_display(SymbolRegions)get_bar_code_object(BarCodeObjects,BarCodeHandle,'all','symbol_regions')get_bar_code_result(BarCodeHandle,'all','decoded_types',DecodedDataTypes)*area_center(SymbolRegions,Area,Rows,Columns)forJ:=0to|DecodedDataStrings|-1by1dev_set_color(Colors[J])select_obj(BarCodeObjects,ObjectSelected,J+1)dev_display(ObjectSelected)endfor*循环获取,并且根据获取的条码数量,设置区域框的颜色if(|DecodedDataStrings|=1)*disp_message(WindowHandle,['Foundbarcode(s)in'+Duration$'3.0f'+'ms:','\nType:'+DecodedDataTypes+'\nData:'+DecodedDataStrings],'window',5*12,12,'black','true')disp_message(WindowHandle,'读取条形码,用时{'+Duration$'3.0f'+'ms}:'+'['+DecodedDataTypes+']'+'='+'“'+DecodedDataStrings+'”','window',12,12,Colors,'true')disp_continue_message(WindowHandle,'black','true')wait_seconds(3)endif*判断读取到数据的数量,当大于1(数字可改为2、3„„)个条码被解码时,显示信息在窗体的第12行,第12列的位置,并按顺序用不同的颜色标注clear_bar_code_model(BarCodeHandle)*关闭条形码解码endwhileclose_framegrabber(AcqHandle)*关闭帧接收器(摄像头)=================================================================================*AutodiscriminationB.hdev**CodegeneratedbyImageAcquisition04*寻找正确的、所需的条码类型的条形码,当寻找到时,hold住图像dev_close_window()dev_open_window(0,0,600,600,'black',WindowHandle)*先关闭活动图形窗口,再打开这个窗口,标识符为WindowHandle;*相对于界面左上角第0行、第0列,大小为300×300像素,颜色为黑色。open_framegrabber('DirectShow',1,1,0,0,0,0,'default',8,'rgb',-1,'false','default','GsouUSB2.0Camera',0,-1,AcqHandle)*注意摄像头的名称grab_image_start(AcqHandle,-1)while(true)grab_image_async(Image,AcqHandle,-1)*开始条形码识别create_bar_code_model([],[],BarCodeHandle)dev_update_var('off')dev_update_pc('off')dev_update_window('off')set_display_font(WindowHandle,14,'mono','true','false')dev_set_draw('margin')dev_set_line_width(3)dev_set_color('forestgreen')*Colors:=['forestgreen','magenta','blue','red','yellow']CodeTypes:=['EAN-13','Code39','EAN-8','Code128','Code93']*CodeTypes:=['auto']get_image_size(Image,Width,Height)dev_display(Image)count_seconds(Start)find_bar_code(Image,SymbolRegions,BarCodeHandle,CodeTypes,DecodedDataStrings)count_seconds(Stop)Duration:=(Stop-Start)*1000dev_display(SymbolRegions)get_bar_code_result(BarCodeHandle,'all','decoded_types',DecodedDataTypes)area_center(SymbolRegions,Area,Rows,Columns)forIdxResult:=0to|DecodedDataStrings|-1by1if(regexp_test(DecodedDataTypes[IdxResult],'EAN-13')#0)Color:='forestgreen'elseColor:='red'endifdev_set_color(Color)select_obj(SymbolRegions,SelectedRegion,IdxResult+1)dev_display(SelectedRegion)disp_message(WindowHandle,DecodedDataTypes[IdxResult]+':'+DecodedDataStrings[IdxResult],'image',Rows[IdxResult],Columns[IdxResult]-160,Color,'true')endfor*if(|DecodedDataStrings|=2)if(DecodedDataTypes='EAN-13')*disp_message(WindowHandle,['Foundbarcode(s)in'+Duration$'3.0f'+'ms:','\nType:'+DecodedDataTypes+'\nData:'+DecodedDataStrings],'window',5*12,12,'black','true')*disp_message(WindowHandle,'读取条形码,用时{'+Duration$'3.0f'+'ms}:'+'['+DecodedDataTypes+']'+'='+'“'+DecodedDataStrings+'”','window',12,12,Colors,'true')disp_continue_message(WindowHandle,'black','true')stop()endif*endifclear_bar_code_model(BarCodeHandle)endwhileclose_framegrabber(AcqHandle)=================================================================================*AutodiscriminationC.hdev**CodegeneratedbyImageAcquisition05*读取每个不同的条码时,显示不同颜色的区域框,获取的条码信息也为相应的区域边框颜色dev_close_window()dev_open_window(0,0,600,600,'black',WindowHandle)*先关闭活动图形窗口,再打开这个窗口,标识符为WindowHandle;*相对于界面左上角第0行、第0列,大小为300×300像素,颜色为黑色。open_framegrabber('DirectShow',1,1,0,0,0,0,'default',8,'rgb',-1,'false','default','GsouUSB2.0Camera',0,-1,AcqHandle)*注意摄像头的名称grab_image_start(AcqHandle,-1)while(true)下载文档到电脑,查找使用更方便grab_image_async(Image,AcqHandle,-1)*开始条形码识别create_

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功