与测量直线的相同,也是为了有些时候加入自己的规则而封装。
函数封装:
函数使用:
NumDistance(矩形之间间距离)
RecHeight(矩形半高)
RecWidth(矩形半宽),
Sigma(平滑系数)
Threshold(灰度值)
ransition(极性)
Select(线选择)
Direction(找线朝向)
上述参数基本都是找线卡尺常规参数,只有最后这个Direction(找线朝向)是单加的。这个是控制卡尺找线方向的,可以直接更人性的使用从里往外,从外往里这样,更加简单直接。
函数代码:
* 参数设置
* Direction(找线朝向),NumDistance(矩形之间间距),RecHeight(矩形半高),RecWidth(矩形半宽),Sigma(平滑系数)
* Threshold(灰度值),Transition(极性),Select(线选择)
gen_empty_obj (RecContour)
RowEdges := []
ColumnEdges := []
try
*获取图像宽高
fit_circle_contour_xld (FindCircle, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi1, EndPhi1, PointOrder1)
get_image_size (Image, Width, Height)
*判断起始点
if (StartPhi <= EndPhi)
for Index := StartPhi to EndPhi by NumDistance
if (Direction == 'ItoO')//从里到外
RectangleRow := Row - Radius * sin(rad(Index))
RectangleColumn := Column + Radius * cos(rad(Index))
gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth)
gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
gen_contour_region_xld (Rectangle, Contours, 'border')
concat_obj (RecContour, Contours, RecContour)
RowEdges := [RowEdges, RowEdge]
ColumnEdges := [ColumnEdges, ColumnEdge]
elseif (Direction == 'OtoI')//从外到里
RectangleRow := Row - Radius * sin(rad(Index))
RectangleColumn := Column + Radius * cos(rad(Index))
gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth)
gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
gen_contour_region_xld (Rectangle, Contours, 'border')
concat_obj (RecContour, Contours, RecContour)
RowEdges := [RowEdges, RowEdge]
ColumnEdges := [ColumnEdges, ColumnEdge]
endif
endfor
elseif (StartPhi >= EndPhi)
for Index := StartPhi to EndPhi by -NumDistance
if (Direction == 'ItoO')//从里到外
RectangleRow := Row - Radius * sin(rad(Index))
RectangleColumn := Column + Radius * cos(rad(Index))
gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth)
gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
gen_contour_region_xld (Rectangle, Contours, 'border')
concat_obj (RecContour, Contours, RecContour)
RowEdges := [RowEdges, RowEdge]
ColumnEdges := [ColumnEdges, ColumnEdge]
elseif (Direction == 'OtoI')//从外到里
RectangleRow := Row - Radius * sin(rad(Index))
RectangleColumn := Column + Radius * cos(rad(Index))
gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth)
gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
gen_contour_region_xld (Rectangle, Contours, 'border')
concat_obj (RecContour, Contours, RecContour)
RowEdges := [RowEdges, RowEdge]
ColumnEdges := [ColumnEdges, ColumnEdge]
endif
endfor
endif
* 显示点位
gen_cross_contour_xld (Cross, RowEdges, ColumnEdges, 6, rad(45))
concat_obj (RecContour, Cross, RecContour)
* 拟合园
gen_contour_polygon_xld (Contour, RowEdges, ColumnEdges)
fit_circle_contour_xld (Contour, 'geotukey', -1, 0, 0, 3, 2, CircleRow, CircleColumn, CircleRadius, CircleStartPhi, CircleEndPhi, PointOrder)
*判断起始点
if (StartPhi <= EndPhi)
gen_circle_contour_xld (Circle, CircleRow, CircleColumn, CircleRadius, CircleStartPhi, CircleEndPhi, 'positive', 1)
elseif (StartPhi >= EndPhi)
gen_circle_contour_xld (Circle, CircleRow, CircleColumn, CircleRadius, CircleEndPhi, CircleStartPhi, 'positive', 1)
endif
catch (Exception)
RowEdges := []
ColumnEdges := []
endtry
return ()