使用halcon选择点拟合成直线求直线角度

原图

源码

read_image (Image, '0.bmp')
dev_clear_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)


binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 100, 100000)


gen_empty_obj (LineRegion)
PointNumber:=0
while (PointNumber<7)
    draw_point (WindowHandle, Row, Column)
    gen_region_points (Region1, Row, Column)
    select_shape_proto (SelectedRegions, Region1, SelectedRegions1, 'overlaps_abs', 1, 5)
    count_obj (SelectedRegions1, Number)
    if(Number>0)
        concat_obj (LineRegion, SelectedRegions1, LineRegion)
        PointNumber:=PointNumber+1
    endif   
endwhile

smallest_circle (LineRegion, Row1, Column1, Radius)


pts_to_best_line (Line, Row1, Column1, |Row1|, RowStart, ColStart, RowEnd, ColEnd)

angle_lx (RowStart, ColStart, RowEnd, ColEnd, Angle)
angle:=deg(Angle)

dev_display (Image)
disp_message (WindowHandle, '角度为:'+angle+'°', 'window', 50, 100, 'red', 'false')
dev_display (Line)

处理结果

使用halcon选择点拟合成直线求直线角度_第1张图片

你可能感兴趣的:(#,Halcon图像处理实例)