当前位置: 首页 > 工具软件 > ANGLE > 使用案例 >

Halcon使用算子angle_lx和angle_ll计算角度

雍光远
2023-12-01

1、计算直线与水平轴X之间的夹角
angle_lx( : : Row1, Column1, Row2, Column2 : Angle)

角度计算方式:将直线看作向量(有方向性),以直线与水平轴的交点为起点(旋转中心)。如果终点在水平轴上方,则夹角为逆时针旋转水平轴到向量的角度(带正号)。如果终点在水平轴下方,则夹角为顺时针旋转水平轴到向量的角度(带负号)。结果取决于定义线条的两点的顺序。

角度表示方式:弧度,-π<=Angle<π

dev_close_window()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
Row1 := 100
Col1 := 100
Row2 := 500
Col2 := 600
Row1Half := (Row1 + Row2)/2
Col1Half := (Col1 + Col2)/2

dev_set_color ('red')
gen_region_line (RegionLines, Row1, Col1, Row2, Col2)
gen_arrow_contour_xld (Arrow1, Row1Half, Col1Half, Row1, Col1, 25, 15)

dev_set_color ('yellow')
gen_region_line (ROI_0, 350, 100, 350, 750)
XRowHalf := 350
XColHalf := (100 + 700)/2
gen_arrow_contour_xld (Arrow, XRowHalf, XColHalf,350, 750, 25, 15)

angle_lx (Row2, Col2, Row1, Col1, Angle)
disp_message (WindowHandle, '红色线角度为:' + deg(Angle), 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'X', 'Image', 345, 765, 'yellow', 'false')
stop()

dev_clear_window()
Row1 := 100
Col1 := 100
Row2 := 500
Col2 := 600
Row1Half := (Row1 + Row2)/2
Col1Half := (Col1 + Col2)/2

dev_set_color ('red')
gen_region_line (RegionLines, Row1, Col1, Row2, Col2)
gen_arrow_contour_xld (Arrow1, Row1Half, Col1Half, Row2, Col2, 25, 15)

dev_set_color ('yellow')
gen_region_line (ROI_0, 350, 100, 350, 750)
XRowHalf := 350
XColHalf := (100 + 700)/2
gen_arrow_contour_xld (Arrow, XRowHalf, XColHalf,350, 750, 25, 15)

angle_lx (Row1, Col1,Row2, Col2,  Angle)
disp_message (WindowHandle, '红色线角度为:' + deg(Angle), 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'X', 'Image', 345, 765, 'yellow', 'false')

2、计算两条直线之间的夹角
angle_ll( : : RowA1, ColumnA1, RowA2, ColumnA2, RowB1, ColumnB1, RowB2, ColumnB2 : Angle)

角度计算方式:该算子计算原理与angle_lx类似,只不过把水平轴替换为任意直线B

角度表示方式:弧度,-π<=Angle<=π

dev_close_window()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 26, 'mono', 'true', 'false')
Row1 := 100
Col1 := 100
Row2 := 500
Col2 := 600
Row1Half := (Row1 + Row2)/2
Col1Half := (Col1 + Col2)/2

Row3 := 400
Col3 := 100
Row4 := 100
Col4 := 500
Row2Half := (Row3 + Row4)/2
Col2Half := (Col3 + Col4)/2

dev_set_color ('red')
gen_region_line (RegionLines, Row1, Col1, Row2, Col2)
gen_arrow_contour_xld (Arrow1, Row1Half, Col1Half, Row1, Col1, 25, 15)

dev_set_color ('blue')
gen_region_line (RegionLines, Row3, Col3, Row4, Col4)
gen_arrow_contour_xld (Arrow1, Row2Half, Col2Half, Row3, Col3, 25, 15)

angle_ll (Row4, Col4,Row3, Col3,  Row2, Col2,Row1, Col1, Angle)
disp_message (WindowHandle, '蓝色线转向红色线角度为:' + deg(Angle), 'window', 12, 12, 'black', 'true')
stop()

dev_clear_window()
Row1 := 100
Col1 := 100
Row2 := 500
Col2 := 600
Row1Half := (Row1 + Row2)/2
Col1Half := (Col1 + Col2)/2

Row3 := 400
Col3 := 100
Row4 := 100
Col4 := 500
Row2Half := (Row3 + Row4)/2
Col2Half := (Col3 + Col4)/2

dev_set_color ('red')
gen_region_line (RegionLines, Row1, Col1, Row2, Col2)
gen_arrow_contour_xld (Arrow1, Row1Half, Col1Half, Row1, Col1, 25, 15)

dev_set_color ('blue')
gen_region_line (RegionLines, Row3, Col3, Row4, Col4)
gen_arrow_contour_xld (Arrow1, Row2Half, Col2Half, Row4, Col4, 25, 15)

angle_ll (Row3, Col3, Row4, Col4, Row2, Col2,Row1, Col1, Angle)
disp_message (WindowHandle, '蓝色线转向红色线角度为:' + deg(Angle), 'window', 12, 12, 'black', 'true')
stop()

dev_clear_window()
Row1 := 100
Col1 := 100
Row2 := 500
Col2 := 600
Row1Half := (Row1 + Row2)/2
Col1Half := (Col1 + Col2)/2

Row5 := 250
Col5 := 20
Row6 := 250
Col6 := 550
Row3Half := (Row5 + Row6)/2
Col3Half := (Col5 + Col6)/2

dev_set_color ('red')
gen_region_line (RegionLines, Row1, Col1, Row2, Col2)
gen_arrow_contour_xld (Arrow1, Row1Half, Col1Half, Row1, Col1, 25, 15)

dev_set_color ('yellow')
gen_region_line (RegionLines, Row5, Col5, Row6, Col6)
gen_arrow_contour_xld (Arrow1, Row3Half, Col3Half, Row6, Col6, 25, 15)

angle_ll (Row2, Col2,Row1, Col1,Row5, Col5, Row6, Col6,  Angle)
disp_message (WindowHandle, '红色线转向黄色色线角度为:' + deg(Angle), 'window', 12, 12, 'black', 'true')
stop()

dev_clear_window()
Row1 := 100
Col1 := 100
Row2 := 500
Col2 := 600
Row1Half := (Row1 + Row2)/2
Col1Half := (Col1 + Col2)/2

Row5 := 250
Col5 := 20
Row6 := 250
Col6 := 550
Row3Half := (Row5 + Row6)/2
Col3Half := (Col5 + Col6)/2

dev_set_color ('red')
gen_region_line (RegionLines, Row1, Col1, Row2, Col2)
gen_arrow_contour_xld (Arrow1, Row1Half, Col1Half, Row1, Col1, 25, 15)

dev_set_color ('yellow')
gen_region_line (RegionLines, Row5, Col5, Row6, Col6)
gen_arrow_contour_xld (Arrow1, Row3Half, Col3Half, Row6, Col6, 25, 15)

angle_ll (Row5, Col5, Row6, Col6, Row2, Col2,Row1, Col1, Angle)
disp_message (WindowHandle, '黄色线转向红色线角度为:' + deg(Angle), 'window', 12, 12, 'black', 'true')

3、计算一条直线的方向
line_orientation( : : RowBegin, ColBegin, RowEnd, ColEnd : Phi)

角度计算方式:当直线(无方向性)大致位于1、3象限的方向,角度为正。当直线大致位于2、4象限的方向,角度为负。

角度表示方式:弧度,-π/2<Phi<=π/2

---

参考文献

Halcon的angle_ll和angle_lx角度的解析 - 木乔ni - 博客园

 类似资料: