图片下载路径
链接:https://pan.baidu.com/s/1kqeEg-bcK5pdYTJDyx4E3w
提取码:tpo7
代码
* 1.加载图片 ***************************************************
dev_update_window ('off')
dev_close_window ()
* 读取图片 ************
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, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Fuse)
set_display_font (WindowID, 12, 'mono', 'true', 'false')
* 2.设置矩形处理区域 *************************************************
* draw_rectangle2 (WindowID, Row, Column, Angle, Length1, Length2)
Row := 297
Column := 545
Length1 := 80
Length2 := 10
Angle := rad(90)
gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2)
* 3.生成测量对象 *****************************************************
gen_measure_rectangle2 (Row, Column, Angle, Length1, Length2, Width, Height, 'bilinear', MeasureHandle)
dev_display (Fuse)
dev_display (ROI)
stop ()
* 4.执行测量 *****************************************************
* 结果 EdgeFirst 组第一个边缘数组 EdgeSecond 组第二个边缘数组
* 结果 黑色区域宽度 IntraDistance
* 结果 黑色区域间距 InterDistance
measure_pairs (Fuse, MeasureHandle, 1, 1, 'negative', 'all', \
RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, \
RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, \
IntraDistance, InterDistance)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* 5.显示测量结果 *****************************************************
* 循环显示 检测边缘对(黑色区域、保险丝宽度)
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 ('blue')
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 ()
close_measure (MeasureHandle)
dev_update_window ('on')
dev_clear_window ()