跟我学机器视觉example.docx

上传人:b****6 文档编号:7838431 上传时间:2023-01-26 格式:DOCX 页数:6 大小:16.33KB
下载 相关 举报
跟我学机器视觉example.docx_第1页
第1页 / 共6页
跟我学机器视觉example.docx_第2页
第2页 / 共6页
跟我学机器视觉example.docx_第3页
第3页 / 共6页
跟我学机器视觉example.docx_第4页
第4页 / 共6页
跟我学机器视觉example.docx_第5页
第5页 / 共6页
点击查看更多>>
下载资源
资源描述

跟我学机器视觉example.docx

《跟我学机器视觉example.docx》由会员分享,可在线阅读,更多相关《跟我学机器视觉example.docx(6页珍藏版)》请在冰豆网上搜索。

跟我学机器视觉example.docx

跟我学机器视觉example

HALCON学习例程中文-IC引脚测量

路径-------C:

\ProgramFiles\MVTec\HALCON-10.0\examples\hdevelop\Applications\Measuring-2D\measure_pin.hdev

∙LeadMeasurement:

Examplefortheapplicationofthemeasureobject

∙includingalotofvisualizationoperators.

∙First,thelengthoftheleadsismeasured,then,theirwidthanddistancefromeachother.

∙First,readintheimageandinitializetheprogram

Read_image(Image,'icpin')

****取得图像第一通道的指针,同时得到图像宽度高度**

Get_image_pointer1(Image,Pointer,Type,Width,Height)

*get_image_pointer1(Image:

:

:

Pointer,Type,Width,Height);获得图像的数据。

如:

类型(='字节',''',uint2int2等等)和图像的尺寸(的宽度和高度)

Dev_close_window()

dev_close_window(:

:

:

)  关闭活跃的图形窗口。

Dev_open_window_fit_image(Image,0,0,509,509,WindowHandle)

设置窗口自适应图片,获得句柄

Set_display_font(WindowHandle,14,'mono','true','false')

内部程序,设置字体

dev_display(Image)

****显示图像如下:

************

∙DefineanddisplaytherectangularROIswithinwhichtheedgeswillbedetected//ROI设置

Dev_set_draw('margin')

Dev_se_tline_width(3)

Row:

=55

RowBottom:

=955

Column:

=200

Phi:

=rad(-90)

Length1:

=50

Length2:

=35

devsetcolor('gray')

gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)

gen_rectangle2(Rectangle,RowBottom,Column,Phi,Length1,Length2)

创建ROI的矩形显示区域

*******测量位置如绿色矩形所示下:

********

Disp_continue_message(WindowHandle,'black','true')

显示‘继续’信息

stop()

∙CreateameasureobjectfortheROIatthetopoftheimage.

*获取一阶灰度剖面图的插值方法,测量矩形框与图像坐标系之间有角度时生效*

Interpolation:

='nearest_neighbor'

********生成测量矩形框,先测上部********

Gen_measure_rectangle2(Row,Column,Phi,Length1,Length2,Width,Height,Interpolation,MeasureHandle)

∙Determinealledgesandcalculatetheleadheightatthetopoftheimage//垂直与矩形的直线边缘的提取。

Sigma:

=1.0

Threshold:

=30

Transition:

='all'

Select:

='all'

***********进行测量*********

measure_pos(Image,MeasureHandle,Sigma,Threshold,Transition,Select,RowEdge,ColumnEdge,Amplitude,Distance)

提取与矩形或环状弧垂直的直线边缘。

LeadLength1:

=Distance

∙Displaytheresults

devsetcolor('white')

**********将测量结果画出********

disp_line(WindowHandle,RowEdge,ColumnEdge-Length2,RowEdge,ColumnEdge+Length2)

disp_message(WindowHandle,'LeadLength:

'+LeadLength1$'.2f','window',RowEdge[1]+40,ColumnEdge[1]+100,'yellow','false')

程序写入文本信息

∙Shiftthemeasureobjectanddeterminetheleadheightatthebottomoftheimage

*******转移测量框至新的参考坐标点,及测量下部*****

translate_measure(MeasureHandle,RowBottom,Column)

***********进行测量*********

measure_pos(Image,MeasureHandle,Sigma,Threshold,Transition,Select,RowEdge,ColumnEdge,Amplitude,Distance)

LeadLength2:

=Distance

∙Displaytheresults

devsetcolor('white')

**********将测量结果画出********

disp_line(WindowHandle,RowEdge,ColumnEdge-Length2,RowEdge,ColumnEdge+Length2)

disp_message(WindowHandle,'LeadLength:

'+LeadLength2$'.2f','window',360,ColumnEdge[1]+100,'red','false')

∙Closethemeasure

close_measure(MeasureHandle)

清除一个测试对象。

Disp_continue_message(WindowHandle,'black','true')

等待用户操作是否继续

stop()

∙Now,defineanddisplayarectangularROIperpendiculartotheleadsandcreatethemeasure

dev_display(Image)

Row:

=47

Column:

=485

Phi:

=0

Length1:

=420

Length2:

=8

Interpolation:

='nearest_neighbor'

devsetcolor('black')

*****创建新的测量矩形ROI,如图蓝色矩形:

*****

gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)

创建ROI矩形

gen_measure_rectangle2(Row,Column,Phi,Length1,Length2,Width,Height,Interpolation,MeasureHandle)

垂直与矩形的直线边缘的提取。

∙Determinealledgepairsthathaveanegativetransition,i.e.,edgepairs

∙thatenclosedarkregions.

Sigma:

=1.0

Threshold:

=30

Transition:

='negative'

Select:

='all'

*********进行测量计算并显示结果********

measure_pairs(Image,MeasureHandle,Sigma,Threshold,Transition,Select,RowEdgeFirst,ColumnEdgeFirst,AmplitudeFirst,RowEdgeSecond,ColumnEdgeSecond,AmplitudeSecond,IntraDistance,InterDistance)

提取测量与矩形或环状弧垂直的直线边缘。

dispcontinuemessage(WindowHandle,'black','true')

stop()

devsetcolor('white')

disp_line(WindowHandle,RowEdgeFirst,ColumnEdgeFirst,RowEdgeSecond,ColumnEdgeSecond)

avgLeadWidth:

=sum(IntraDistance)/|IntraDistance|

avgLeadDistance:

=sum(InterDistance)/|InterDistance|

numLeads:

=|IntraDistance|

disp_message(WindowHandle,'NumberofLeads:

'+numLeads,'window',200,100,'yellow','false')

disp_message(WindowHandle,'AverageLeadWidth:

'+avgLeadWidth$'.2f','window',260,100,'yellow','false')

disp_message(WindowHandle,'AverageLeadDistance:

'+avgLeadDistance$'.2f','window',320,100,'yellow','false')

信息显示

dispcontinuemessage(WindowHandle,'black','true')

dispcontinuemessage(WindowHandle,'black','true')

stop()

∙Zoomintovisualizethemeasurementresultsinmoredetail.

∙First,defineanddisplaythezoomwindow.

Row1:

=0

Column1:

=600

Row2:

=100

Column2:

=700

devsetcolor('blue')

*******设置放大区域矩形并显示,图中绿色矩形****

disp_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)

显示和坐标轴对齐的矩形。

dispcontinuemessage(WindowHandle,'black','true')

stop()

∙Then,zoomtheimageanddisplaytheresults.

******设置图像放大区域并显示***********

Dev_set_part(Row1,Column1,Row2,Column2)

修改显示图像部分。

dev_display(Image)

dev_set_color('black')

******画出测量矩形ROI和测得的边缘如图*******

dev_display(Rectangle)

pdispedge_marker(RowEdgeFirst,ColumnEdgeFirst,Phi,5,'white',3,WindowHandle)

pdispedge_marker(RowEdgeSecond,ColumnEdgeSecond,Phi,5,'white',3,WindowHandle)

∙Closethemeasure

close_measure(MeasureHandle)

∙Resetthedisplayparameters.

devsetpart(0,0,Height-1,Width-1)

devsetdraw('fill')

devsetline_width

(1)

Copyright©2014志强智达

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 交通运输

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1