Halcon uses the operators angle_lx and angle_ll to calculate the angle

1. Calculate the angle between the line and the horizontal axis X
angle_lx( : : Row1, Column1, Row2, Column2 : Angle)

Angle calculation method: The straight line is regarded as a vector (with directionality), and the intersection of the straight line and the horizontal axis is the starting point (the center of rotation). If the end point is above the horizontal axis, the included angle is the angle (with a positive sign) that rotates the horizontal axis counterclockwise to the vector. If the end point is below the horizontal axis, the included angle is the angle (with a negative sign) rotated clockwise from the horizontal axis to the vector. The result depends on the order of the two points that define the line.

Angle representation: radians, -π<=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. Calculate the angle between two lines
angle_ll( : : RowA1, ColumnA1, RowA2, ColumnA2, RowB1, ColumnB1, RowB2, ColumnB2 : Angle)

Angle calculation method: The calculation principle of this operator is similar to that of angle_lx, except that the horizontal axis is replaced by any straight line B

Angle representation: radians, -π<=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. Calculate the direction of a straight line
line_orientation( : : RowBegin, ColBegin, RowEnd, ColEnd : Phi)

Angle calculation method: When the straight line (without directionality) is roughly in the direction of the 1st and 3rd quadrants, the angle is positive. When the line is roughly in the direction of quadrants 2 and 4, the angle is negative.

Angle representation: radians, -π/2<Phi<=π/2

---

references

Analysis of Halcon's angle_ll and angle_lx angles

Guess you like

Origin blog.csdn.net/libaineu2004/article/details/123318370