检测保险丝距离

 

 

 代码


read_image (Image, '2')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
mean_image (Image, ImageMean, 3, 3)
threshold (ImageMean, Region, 128, 255)
opening_rectangle1 (Region, RegionOpening, 10, 10)
closing_rectangle1 (RegionOpening, RegionClosing, 1, 10)
fill_up_shape (RegionClosing, RegionFillUp, 'area', 1, 100)
connection (RegionFillUp, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 3229.4, 15256.1)
smallest_rectangle1 (SelectedRegions, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (ImageMean, Rectangle, ImageReduced)
** 获取边缘
edges_color_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
**(将一个XLD轮廓分割为直线段、圆(圆弧)、椭圆弧。)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
** 根据弧度查找圆弧
select_shape_xld (ContoursSplit, SelectedXLD, 'circularity', 'and', 0.3, 1)
**迂合园
fit_circle_contour_xld (SelectedXLD, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
** 生成轮廓圆
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)

gen_region_contour_xld (ContCircle, Region1, 'filled')
union1 (Region1, RegionUnion)

smallest_circle (RegionUnion, Row3, Column3, Radius1)

gen_cross_contour_xld (Cross, Row3, Column3, 10, 0.785398)
gen_cross_contour_xld (Cross1, Row3, Column3, 20, 0)

** 生成类似一条直线
gen_rectangle2 (Rectangle1, Row3, Column3, 0, 60, 1)
** 将截取的一段设置白色 为后面的相交排除干扰
paint_region (Rectangle, Image, ImageResult, 255, 'fill')

binary_threshold (ImageResult, Region2, 'max_separability', 'dark', UsedThreshold)
connection (Region2, ConnectedRegions1)

select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 24805.1, 27811.8)
**相交
intersection (Rectangle1, SelectedRegions1, RegionIntersection)
area_center (RegionIntersection, Area, Row4, Column4)
gen_cross_contour_xld (Cross2, Row4, Column4, 20, 0.785398)
**计算2点距离
distance_pp ( Row3, Column3, Row4, Column4, Distance)
disp_message (WindowHandle, Distance, 'Image', Row4, Column4, 'black', 'true')
** 生成一条线
gen_region_line (RegionLines, Row3, Column3, Row4, Column4)

 

posted @ 2024-07-05 17:32  陌念  阅读(7)  评论(0)    收藏  举报