Halcon Stage Is hdev的代码实例.docx
- 文档编号:29476648
- 上传时间:2023-07-23
- 格式:DOCX
- 页数:30
- 大小:22.33KB
Halcon Stage Is hdev的代码实例.docx
《Halcon Stage Is hdev的代码实例.docx》由会员分享,可在线阅读,更多相关《Halcon Stage Is hdev的代码实例.docx(30页珍藏版)》请在冰豆网上搜索。
HalconStageIshdev的代码实例
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|-1by1
dev_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)
*关闭条形码解码
endwhile
close_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)*1000
dev_display(SymbolRegions)
get_bar_code_result(BarCodeHandle,'all','decoded_types',DecodedDataTypes)
area_center(SymbolRegions,Area,Rows,Columns)
forIdxResult:
=0to|DecodedDataStrings|-1by1
if(regexp_test(DecodedDataTypes[IdxResult],'EAN-13')#0)
Color:
='forestgreen'
else
Color:
='red'
endif
dev_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
*endif
clear_bar_code_model(BarCodeHandle)
endwhile
close_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_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)*1000
dev_display(SymbolRegions)
get_bar_code_result(BarCodeHandle,'all','decoded_types',DecodedDataTypes)
area_center(SymbolRegions,Area,Rows,Columns)
forIdxResult:
=0to|DecodedDataStrings|-1by1
dev_set_color(Colors[IdxResult])
select_obj(SymbolRegions,SelectedRegion,IdxResult+1)
dev_display(SelectedRegion)
disp_message(WindowHandle,DecodedDataTypes[IdxResult]+':
'+DecodedDataStrings[IdxResult],'image',Rows[IdxResult],Columns[IdxResult]-160,Colors[IdxResult],'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
*endif
clear_bar_code_model(BarCodeHandle)
endwhile
close_framegrabber(AcqHandle)
=================================================================================
*AutodiscriminationD.hdev
*
*CodegeneratedbyImageAcquisition06
*读取条码的方向值,但是值是为什么是这个数值,还不清楚。
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_display(Image)
dev_set_draw('margin')
dev_set_line_width(3)
dev_set_color('green')
set_display_font(WindowHandle,14,'mono','true','false')
get_bar_code_param(BarCodeHandle,'orientation',InputOrient)
get_bar_code_param(BarCodeHandle,'orientation_tol',InputOrientTol)
Mode:
='Defaultorientation'
set_bar_code_param(BarCodeHandle,['orientation','orientation_tol'],[InputOrient,InputOrientTol])
count_seconds(Seconds1)
find_bar_code(Image,SymbolRegions,BarCodeHandle,'EAN-13',DecodedDataStrings)
count_seconds(Seconds2)
Time:
=(Seconds2-Seconds1)*1000
dev_display(Image)
dev_display(SymbolRegions)
get_bar_code_result(BarCodeHandle,'all','orientation',Orientation)
area_center(SymbolRegions,Area,Row,Col)
*gen_arrow_contour_xld(Arrow,Row+sin(rad(Orientation))*70,Col-cos(rad(Orientation))*70,Row-sin(rad(Orientation))*70,Col+cos(rad(Orientation))*70,25,25)
*dev_display(Arrow)
*暂时获取方向的箭头Arrow,只能获取一个静态的,但动态时,就出错?
forI:
=0to|Row|-1by1
disp_message(WindowHandle,'Orientation='+Orientation[I]$'.1f'+chr(0xb0),'image',Row[I]-30,Col[I]-120,'black','true')
endfor
Message:
=Mode+':
'+InputOrient+chr(0xb0)+'+/-'+InputOrientTol+chr(0xb0)
Message[1]:
=|Row|+'code(s)foundin'+Time$'.1f'+'ms'
disp_message(WindowHandle,Message,'window',12,12,'black','true')
if(|Orientation|>=1)
disp_continue_message(WindowHandle,'black','true')
stop()
endif
clear_bar_code_model(BarCodeHandle)
endwhile
close_framegrabber(AcqHandle)
=================================================================================
*Camera2DCodeRead.hdev
*
*2DCodegeneratedbyImageAcquisition01
*QRCode
dev_close_window()
dev_open_window(0,0,400,400,'black',WindowHandle)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Halcon Stage Is hdev的代码实例 hdev 代码 实例