例程功能
检查倒角后铸件的细长孔之间的距离。
代码如下
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)
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)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
count_seconds (Seconds1)
n := 10
for i := 1 to n by 1
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')
dev_set_line_width (1)
* disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_clear_window ()
要点
gen_measure_arc
——采用圆弧arc作为测量区域,这是和上个例程不同的地方;
CenterRow
:入参,圆弧中心的行坐标;
CenterCol
:入参,圆弧中心的纵坐标;
Radius
:入参,圆弧半径;
AngleStart
:入参,弧度的起始角)以弧度为单位);
AngleExtent
:入参,弧度的角范围(以弧度为单位);
AnnulusRadius
:入参,圆弧环形半径;
Width
:入参,待处理图像的宽度;
Height
:入参,待处理图像的高度;
Interpolation
:入参,插值的形式;
MeasureHandle
:出参,测量对象句柄;measure_pos
——提取垂直于矩形或环形弧的直边;
Image
:入参,输入图片;
MeasureHandle
:入参,测量对象句柄;
Sigma
:入参,高斯模糊参数;
Threshold
:入参,最小边沿振幅;
Transition
:入参,亮/暗或暗/亮边缘;
Select
:入参,终点选择;
RowEdge
:出参,边缘的中心行值(纵坐标);
ColumnEdge
:出参,边缘的中心列值(横坐标);
Amplitude
:出参,边的边缘振幅(带符号);
Distance
:出参,连续边之间的距离;measure_pos
返回的是一个数组,索引1为最小值,索引2为最大值,示例代码中用distance_pp
取点计算了最短距离
measure_pos (Zeiss1, MeasureHandle, 1, 10, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
distance_pp (RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2], IntermedDist)