二十一.1D Measuring 之二(例子1-3)

例1.测量保险丝宽度

* fuse.hdev: measuring the width of a fuse wire
dev_update_window ('off')
dev_close_window ()
* ****
* step: acquire image
* ****
read_image (Fuse, 'fuse')
get_image_size (Fuse, Width, Height)
dev_open_window_fit_image (Fuse, 0, 0, Width, Height, WindowID)
set_display_font (WindowID, 12, 'Courier', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Fuse)
set_display_font (WindowID, 12, 'courier', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: create measure object
* ****
* -> specify ROI
Row := 297
Column := 545
Length1 := 80
Length2 := 10
Angle := rad(90)
gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2) //产生和水平方向成90的矩形ROI//
* -> create measure object
gen_measure_rectangle2 (Row, Column, Angle, Length1, Length2, Width, Height, 'bilinear', MeasureHandle)//产生和水平方向成90的测量矩形句柄//
dev_display (ROI)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: measure
* ****
measure_pairs (Fuse, MeasureHandle, 1, 1, 'negative', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
disp_continue_message (WindowID, 'black', 'true')//返回测量值//

stop ()
* ****
* step: visualize results
* ****
for i := 0 to |RowEdgeFirst|-1 by 1//显示测量距离//
    gen_contour_polygon_xld (EdgeFirst, [-sin(Angle+rad(90))*Length2+RowEdgeFirst[i], -sin(Angle-rad(90))*Length2+RowEdgeFirst[i]], [cos(Angle+rad(90))*Length2+ColumnEdgeFirst[i], cos(Angle-rad(90))*Length2+ColumnEdgeFirst[i]])//以在第一类边缘端点连线产生一直线//
    gen_contour_polygon_xld (EdgeSecond, [-sin(Angle+rad(90))*Length2+RowEdgeSecond[i], -sin(Angle-rad(90))*Length2+RowEdgeSecond[i]], [cos(Angle+rad(90))*Length2+ColumnEdgeSecond[i], cos(Angle-rad(90))*Length2+ColumnEdgeSecond[i]])//以在第二类边缘端点像素点连线产生一直线//
    dev_set_color ('cyan')
    dev_display (EdgeFirst)
    dev_set_color ('magenta')
    dev_display (EdgeSecond)
    dev_set_color ('blue')
    if (i = 0)//设置光标位置//
        set_tposition (WindowID, RowEdgeFirst[i] + 5, ColumnEdgeFirst[i]+20)
    else
        set_tposition (WindowID, RowEdgeFirst[i] - 40, ColumnEdgeFirst[i]+20)
    endif
    write_string (WindowID, 'width: '+IntraDistance[i]+' pix')//在指定光标位置写入制定内容//
endfor
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: destroy measure object
* ****
close_measure (MeasureHandle)
dev_update_window ('on')
dev_clear_window ()

结果:

  

 

例2.测量铸件尺寸

Example for the application of the measure package
* including a lot of visualization operators
*
read_image (Zeiss1, 'zeiss1')
get_image_size (Zeiss1, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Zeiss1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* draw_circle (WindowHandle, Row, Column, Radius)
Row := 275
Column := 335
Radius := 107
AngleStart := -rad(55)
AngleExtent := rad(170)
dev_set_draw ('fill')
dev_set_color ('green')
dev_set_line_width (1)
get_points_ellipse (AngleStart+AngleExtent, Row, Column, 0, Radius, Radius, RowPoint, ColPoint)

//得到椭圆上满足和椭圆中心连线成115度的直线的交点坐标//
disp_arc (WindowHandle, Row, Column, AngleExtent, RowPoint, ColPoint)
dev_set_line_width (3)
gen_measure_arc (Row, Column, Radius, AngleStart, AngleExtent, 10, Width,

Height, 'nearest_neighbor', MeasureHandle)
//产生圆弧测量句柄,测量角度范围为-55度到170度,沿半径方向宽度为10*2,这样一个扇环//
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
count_seconds (Seconds1)
n := 10
for i := 1 to n by 1//执行10次测量取平均//   

measure_pos (Zeiss1, MeasureHandle, 1, 10, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
endfor
count_seconds (Seconds2)
Time := (Seconds2-Seconds1)/n//计算程序段执行时间//  
disp_continue_message (WindowHandle, 'black', 'true')
* stop ()
distance_pp (RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2], IntermedDist)
//计算第二个和第三个边缘点之间的距离//  
* dev_display (Zeiss1)
dev_set_color ('red')
* disp_circle (WindowHandle, RowEdge, ColumnEdge, RowEdge-RowEdge+1)
disp_line (WindowHandle, RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2])
dev_set_color ('yellow')
disp_message (WindowHandle, 'Distance: '+IntermedDist, 'image', 250, 80, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\zeiss_result')
close_measure (MeasureHandle)
dev_set_line_width (1)
* disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_clear_window ()

二十一.1D <wbr>Measuring <wbr>之二(例子1-3)

例3.基于模糊算子测量的IC卡检测。

* Example for the application of the fuzzy measure tool
* including a lot of visualization operators
*
dev_close_window ()
read_image (Image, 'board/board-06')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
stop ()
*
* --- Fuzzy Measure:
Row1 := 305.5
Col1 := 375.5
Phi1 := 0.982
Length1 := 167
Length2 := 8
gen_measure_rectangle2 (Row1, Col1, Phi1, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle1)
Row2 := 188.5
Col2 := 202.5
Phi2 := Phi1-rad(180)
gen_measure_rectangle2 (Row2, Col2, Phi2, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle2)
* create a fuzzy member function to select edge pairs of size of the chip pins (about 11 Pixels)
create_funct_1d_pairs ([0.0, 0.3], [1.0,0.0], FuzzyAbsSizeDiffFunction)
set_fuzzy_measure_norm_pair (MeasureHandle1, 11.0, 'size_abs_diff', FuzzyAbsSizeDiffFunction)
set_fuzzy_measure_norm_pair (MeasureHandle2, 11.0, 'size_abs_diff', FuzzyAbsSizeDiffFunction)
fuzzy_measure_pairs (Image, MeasureHandle1, 1, 30, 0.5, 'positive', RowEdgeFirst1, ColumnEdgeFirst1, AmplitudeFirst1, RowEdgeSecond1, ColumnEdgeSecond1, AmplitudeSecond1, RowEdgeMiddle1, ColumnEdgeMiddle1, FuzzyScore1, IntraDistance1, InterDistance1)
fuzzy_measure_pairs (Image, MeasureHandle2, 1, 30, 0.5, 'positive', RowEdgeFirst2, ColumnEdgeFirst2, AmplitudeFirst2, RowEdgeSecond2, ColumnEdgeSecond2, AmplitudeSecond2, RowEdgeMiddle2, ColumnEdgeMiddle2, FuzzyScore2, IntraDistance2, InterDistance2)
*
* --- Visualisation:
dev_display (Image)
* measuring area
dev_display_measure_object (Row1, Col1, Phi1, Length1, Length2)
dev_display_measure_object (Row2, Col2, Phi2, Length1, Length2)
* edge pairs
dev_set_draw ('fill')
pin := 1
dev_display_profile_points ([RowEdgeFirst1,RowEdgeSecond1], [ColumnEdgeFirst1,ColumnEdgeSecond1], Row1, Col1, Phi1, Length1, Length2)
for I := 0 to |ColumnEdgeFirst1|-1 by 1
    dev_set_color ('yellow')
    disp_message (WindowHandle, 'size:'+IntraDistance1[I]$'.2f'+' score:'+ FuzzyScore1[I]$'.2f', 'image', RowEdgeSecond1[I], ColumnEdgeSecond1[I]+10, 'yellow', 'false')
    MRow := RowEdgeSecond1[I]-5
    MCol := ColumnEdgeSecond1[I]-20
    set_color (WindowHandle, 'white')
    disp_circle (WindowHandle, MRow, MCol, 10)
    set_color (WindowHandle, 'black')
    get_string_extents (WindowHandle, pin, Ascent, Descent, SWidth, SHeight)
    disp_message (WindowHandle, pin, 'window', MRow-SHeight/2, MCol-SWidth/2, 'black', 'false')
    pin := pin+1
endfor
dev_display_profile_points ([RowEdgeFirst2,RowEdgeSecond2], [ColumnEdgeFirst2,ColumnEdgeSecond2], Row2, Col2, Phi2, Length1, Length2)
for I := 0 to |ColumnEdgeFirst2|-1 by 1
    dev_set_color ('yellow')
    disp_message (WindowHandle, 'size:'+IntraDistance2[I]$'.2f'+' score:'+ FuzzyScore2[I]$'.2f', 'image', RowEdgeFirst2[I], ColumnEdgeFirst2[I]+10, 'yellow', 'false')
    MRow := RowEdgeFirst2[I]-5
    MCol := ColumnEdgeFirst2[I]-20
    set_color (WindowHandle, 'white')
    disp_circle (WindowHandle, MRow, MCol, 10)
    set_color (WindowHandle, 'black')
    get_string_extents (WindowHandle, pin, Ascent, Descent, SWidth, SHeight)
    disp_message (WindowHandle, pin, 'window', MRow-SHeight/2, MCol-SWidth/2, 'black', 'false')
    pin := pin+1
endfor
stop ()
close_measure (MeasureHandle1)
close_measure (MeasureHandle2)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值