主程序
read_image (image_BN, 'C:/训练照片/16')
threshold(image_BN,Regions,0,30)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1000, 9999999999)
dismember_outline (SelectedRegions, Rows, Columns)
* read_image (image_S, 'S.bmp')
dismember_outline函数实现
gen_contour_region_xld (Region, Contours, 'border')
smooth_contours_xld (Contours, SmoothedContours, 11)
gen_region_contour_xld (SmoothedContours, SmoothedRegion, 'filled')
gen_contour_region_xld (SmoothedRegion, Contours, 'border')segment_contours_xld (Contours, Segments, 'lines_circles', 5, 4, 3.5)Colors := ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan', 'orange']IntersectionPoints := []dev_update_off ()
count_obj (Segments, NumSegments)for i := 1 to NumSegments by 1select_obj (Segments, CurrentSegment, i)ColorIndex := (i-1) % 7dev_set_color (Colors[ColorIndex])dev_display (CurrentSegment)get_contour_xld (CurrentSegment, Row, Col)PointCount := |Row|fit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (Dist <= 1.0 and PointCount >= 5)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifelseif (PointCount >= 10)tryfit_circle_contour_xld (CurrentSegment, 'geometric', -1, 0, 0, 3, 2, RowC, ColC, Radius, StartPhi, EndPhi, Order)if (Radius > 0 and abs(EndPhi - StartPhi) >= rad(15))if (Order == 'positive')StartPointRow := RowC + Radius * sin(StartPhi)StartPointCol := ColC + Radius * cos(StartPhi)EndPointRow := RowC + Radius * sin(EndPhi)EndPointCol := ColC + Radius * cos(EndPhi)elseStartPointRow := RowC + Radius * sin(EndPhi)StartPointCol := ColC + Radius * cos(EndPhi)EndPointRow := RowC + Radius * sin(StartPhi)EndPointCol := ColC + Radius * cos(StartPhi)endifif (i == 1)IntersectionPoints := [IntersectionPoints, StartPointRow, StartPointCol, EndPointRow, EndPointCol]elseIntersectionPoints := [IntersectionPoints, EndPointRow, EndPointCol]endifelsefit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 10, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifendifcatch (Exception)fit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 10, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifendtryelsefit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 10, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifendifendif
endfor* 闭合处理:确保首尾点相连
if (NumSegments >= 1 and |IntersectionPoints| >= 4)* 正确访问数组元素(Row和Col交替存储)FirstRow := IntersectionPoints[0]FirstCol := IntersectionPoints[1]LastRow := IntersectionPoints[|IntersectionPoints|-2]LastCol := IntersectionPoints[|IntersectionPoints|-1]* 如果未闭合则添加闭合点if (sqrt((FirstRow - LastRow)*(FirstRow - LastRow) + (FirstCol - LastCol)*(FirstCol - LastCol)) > 2)IntersectionPoints := [IntersectionPoints, FirstRow, FirstCol]endif
endifdev_set_color ('white')
dev_set_draw ('fill')
dev_set_line_width (1)* 正确显示交点
for j := 0 to |IntersectionPoints|/2 - 1 by 1Row := IntersectionPoints[2*j]Col := IntersectionPoints[2*j+1]gen_circle (Circle, Row, Col, 3)dev_display (Circle)
endfordev_update_on ()
