发布时间:2022-09-28 08:30
read_image (Image, ‘C:/Users/Public/Documents/MVTec/HALCON-12.0/examples/images/clip.png’)
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, ‘black’, WindowHandle)
dev_display (Image)
dev_set_color (‘black’)
RowA1:=255
ColA1:=10
RowA2:=255
ColA2:=500
disp_line (WindowHandle, RowA1, ColA1, RowA2, ColA2)
RowB1:=255
ColB1:=255
for i:=1 to 360 by 1
RowB2:=255+sin(rad(i))*200
ColB2:=255+cos(rad(i))*200
disp_line (WindowHandle, RowB1, ColB1, RowB2, ColB2)
gen_region_line (RegionLines, RowB1, ColB1, RowB2, ColB2)
*计算区域的方向-3.14~6.28
orientation_region (RegionLines, Phi)
*计算直线的方向-1.57~1.57
line_orientation (RowB1, ColB1, RowB2, ColB2, Phi1)
*计算线段的中心,长度和方向
line_position (RowB1, ColB1, RowB2, ColB2, RowCenter, ColCenter, Length, Phi2)
*计算两直线的夹角0~3.14
angle_ll ( RowA1, ColA1, RowA2, ColA2, RowB1, ColB1, RowB2, ColB2, Angle)
endfor
stop ()
threshold (Image, Dark, 0, 70)
connection (Dark, ConnectedRegions)
*dev_clear_window ()
select_shape (ConnectedRegions, SelectedRegions, ‘area’, ‘and’, 5000, 10000)
orientation_region (SelectedRegions, Phi3)
area_center (SelectedRegions, Area, Row, Column)
dev_set_color (‘red’)
dev_set_draw (‘margin’)
dev_set_line_width (7)
length :=80
disp_arrow (WindowHandle, Row, Column, Row+cos((Phi3+1.57))*length, Column+sin((Phi3+1.57))*length, 3)