跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量
Lead Measurement: Example for the application of the measure object
including a lot of visualization operators.
First, the length of the leads is measured, then, their width and distance from each other.
First, read in the image and initialize the program
readimage (Image, ‘icpin‘)
****取得图像第一通道的指针,同时得到图像宽度高度**
getimagepointer1 (Image, Pointer, Type, Width, Height)
devclosewindow ()
devopenwindowfitimage (Image, 0, 0, 509, 509, WindowHandle)
setdisplayfont (WindowHandle, 14, ‘mono‘, ‘true‘, ‘false‘)
dev_display (Image)
****显示图像如下:************
devsetdraw (‘margin‘)
devsetline_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)
*******测量位置如绿色矩形所示下:********
dispcontinuemessage (WindowHandle, ‘black‘, ‘true‘)
stop ()
*获取一阶灰度剖面图的插值方法,测量矩形框与图像坐标系之间有角度时生效*
Interpolation := ‘nearest_neighbor‘
********生成测量矩形框,先测上部********
genmeasurerectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, Interpolation, MeasureHandle)
Sigma := 1.0
Threshold := 30
Transition := ‘all‘
Select := ‘all‘
***********进行测量*********
measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
LeadLength1 := Distance
devsetcolor (‘white‘)
**********将测量结果画出********
disp_line (WindowHandle, RowEdge, ColumnEdge-Length2, RowEdge, ColumnEdge+Length2)
disp_message (WindowHandle, ‘Lead Length: ‘+LeadLength1$‘.2f‘, ‘window‘, RowEdge[1]+40, ColumnEdge[1]+100, ‘yellow‘, ‘false‘)
*******转移测量框至新的参考坐标点,及测量下部*****
translate_measure (MeasureHandle, RowBottom, Column)
***********进行测量*********
measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
LeadLength2 := Distance
devsetcolor (‘white‘)
**********将测量结果画出********
disp_line (WindowHandle, RowEdge, ColumnEdge-Length2, RowEdge, ColumnEdge+Length2)
disp_message (WindowHandle, ‘Lead Length: ‘+LeadLength2$‘.2f‘, ‘window‘, 360, ColumnEdge[1]+100, ‘red‘, ‘false‘)
close_measure (MeasureHandle)
dispcontinuemessage (WindowHandle, ‘black‘, ‘true‘)
stop ()
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)
genmeasurerectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, Interpolation, MeasureHandle)
Determine all edge pairs that have a negative transition, i.e., edge pairs
that enclose dark regions.
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, ‘Number of Leads: ‘+numLeads, ‘window‘, 200, 100, ‘yellow‘, ‘false‘)
disp_message (WindowHandle, ‘Average Lead Width: ‘+avgLeadWidth$‘.2f‘, ‘window‘, 260, 100, ‘yellow‘, ‘false‘)
disp_message (WindowHandle, ‘Average Lead Distance: ‘+avgLeadDistance$‘.2f‘, ‘window‘, 320, 100, ‘yellow‘, ‘false‘)
dispcontinuemessage (WindowHandle, ‘black‘, ‘true‘)
dispcontinuemessage (WindowHandle, ‘black‘, ‘true‘)
stop ()
Zoom in to visualize the measurement results in more detail.
First, define and display the zoom window.
Row1 := 0
Column1 := 600
Row2 := 100
Column2 := 700
devsetcolor (‘blue‘)
*******设置放大区域矩形并显示,图中绿色矩形****
disp_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
dispcontinuemessage (WindowHandle, ‘black‘, ‘true‘)
stop ()
******设置图像放大区域并显示***********
devsetpart (Row1, Column1, Row2, Column2)
dev_display (Image)
devsetcolor (‘black‘)
******画出测量矩形ROI和测得的边缘如图*******
dev_display (Rectangle)
pdispedge_marker (RowEdgeFirst, ColumnEdgeFirst, Phi, 5, ‘white‘, 3, WindowHandle)
pdispedge_marker (RowEdgeSecond, ColumnEdgeSecond, Phi, 5, ‘white‘, 3, WindowHandle)
close_measure (MeasureHandle)
devsetpart (0, 0, Height-1, Width-1)
devsetdraw (‘fill‘)
devsetline_width(1)
跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量,布布扣,bubuko.com
原文:http://www.cnblogs.com/chita/p/3620773.html