halcon车刀崩边检测

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

list_files ('新建文件夹', 'files', Files)
read_image (Image, Files[0])
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width/1.5, Height/1.5, 'black', WindowHandle)
dev_set_draw ('margin')
dev_set_colored (12)
for Index:=0 to |Files|-1 by 1
    read_image (Image, Files[Index])
edges_sub_pix (Image, Edges, 'canny', 1, 70, 100)
select_contours_xld (Edges, SelectedContours, 'contour_length', 50, 2000, -0.5, 0.5)
union_adjacent_contours_xld (SelectedContours, UnionContours, 10, 1, 'attr_keep')
smooth_contours_xld (UnionContours, SmoothedContours, 5)
smallest_rectangle2_xld (SmoothedContours, Row2, Column1, Phi, Length1, Length2)
gen_rectangle2 (Rectangle, Row2, Column1, Phi, Length1, Length2)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, -Phi, Row2, Column1, HomMat2DRotate)
* hom_mat2d_scale (HomMat2DRotate, 1.5, 1.5, 256, 256, HomMat2DScale)
affine_trans_contour_xld (SmoothedContours, ContoursAffinTrans, HomMat2DRotate)

segment_contours_xld (SmoothedContours, ContoursSplit, 'lines_circles', 5, 4, 2)
select_shape_xld (ContoursSplit, SelectedXLD, ['circularity','contlength'], 'or', [0.01,0], [1,50])
union_adjacent_contours_xld (SelectedXLD, CircleXld, 10, 1, 'attr_keep')
select_shape_xld (CircleXld, SelectedXLD3, 'contlength', 'and', 0, 200)
obj_diff (CircleXld, SelectedXLD3, CircleXld)
obj_diff (ContoursSplit, SelectedXLD, LinesXld)
concat_obj (LinesXld, SelectedXLD3, LinesXld)
union_adjacent_contours_xld (LinesXld, LinesXld, 10, 1, 'attr_keep')

gen_empty_obj (SelectedXLD2)
gen_empty_obj (SelectedXLD1)

fit_circle_contour_xld (CircleXld, 'geotukey', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
if(|Row|>0)
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
    distance_cc (ContCircle, CircleXld, 'point_to_segment', DistanceMin, DistanceMax)
difference_closed_contours_xld (CircleXld, ContCircle, ContoursDifference)
difference_closed_contours_xld (ContCircle, CircleXld, ContoursDifference1)
select_shape_xld (ContoursDifference1, SelectedXLD2, ['rect2_len2','compactness'], 'and', [1,0], [50,50])
select_shape_xld (ContoursDifference, SelectedXLD1, ['rect2_len2','compactness'], 'and', [1,0], [50,50])
endif
 fit_line_contour_xld (LinesXld, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
segment_contours_xld (LinesXld, ContoursSplitLines, 'lines_circles', 5, 5, 1)
select_shape_xld (ContoursSplitLines, SelectedXLDLines,  ['circularity','contlength'], 'or', [0.015,0], [1,30])

smallest_rectangle2_xld (SelectedXLDLines, Row3, Column2, Phi1, Length11, Length21)
gen_region_contour_xld (SelectedXLDLines, Region, 'filled')
dilation_circle (Region, RegionDilation, 3.5)


dev_display (Image)
dev_display (SelectedXLD2)
dev_display (SelectedXLD1)
dev_display (SelectedXLDLines)
dev_display (RegionDilation)
stop()
endfor

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/cashmood/article/details/111941478
今日推荐