Halcon中关于角度计算和测量拟合的算子详解

Halcon中关于⾓度计算和测量拟合的算⼦详解
⾓度计算算⼦简介
1、计算直线与⽔平轴之间的夹⾓
angle_lx( : : Row1, Column1, Row2, Column2 : Angle)
⾓度计算⽅式:将直线看作向量(有⽅向性),以直线与⽔平轴的交点为起点(旋转中⼼)。如果终点在⽔平轴上⽅,则夹⾓为逆时针旋转⽔平轴到向量的⾓度(带正号)。如果终点在⽔平轴下⽅,则夹⾓为顺时针旋转⽔平轴到向量的⾓度(带负号)。结果取决于定义线条的两点的顺序。
⾓度表⽰⽅式:弧度,-π<=Angle<π
2、计算两条直线之间的夹⾓
angle_ll( : : RowA1, ColumnA1, RowA2, ColumnA2, RowB1, ColumnB1, RowB2, ColumnB2 : Angle)
⾓度计算⽅式:该算⼦计算原理与angle_lx类似,只不过把⽔平轴替换为任意直线B
⾓度表⽰⽅式:弧度,-π<=Angle<=π
3、计算⼀条直线的⽅向
line_orientation( : : RowBegin, ColBegin, RowEnd, ColEnd : Phi)
⾓度计算⽅式:当直线(⽆⽅向性)⼤致位于1、3象限的⽅向,⾓度为正。当直线⼤致位于2、4象限的⽅向,⾓度为负。
⾓度表⽰⽅式:弧度,-π/2<Phi<=π/2
4、计算⼀条直线的参数
line_position( : : RowBegin, ColBegin, RowEnd, ColEnd : RowCenter, ColCenter, Length, Phi)
⾓度计算⽅式:同算⼦ line_orientation。
⾓度表⽰⽅式:弧度,-π/2<Phi<=π/2
5、计算区域等效椭圆的参数
elliptic_axis(Regions : : : Ra, Rb, Phi)
⾓度计算⽅式:该区域等效椭圆的主轴(⽆⽅向性)相对于⽔平轴(有⽅向性)的⾓度。
⾓度表⽰⽅式:弧度,-π/2<Phi<=π/2
6、计算区域的最⼩仿射外接矩形的参数
smallest_rectangle2(Regions : : : Row, Column, Phi, Length1, Length2)
⾓度计算⽅式:同算⼦elliptic_axis
⾓度表⽰⽅式:弧度,-π/2<Phi<=π/2
7、计算区域的⽅向
orientation_region(Regions : : : Phi)
⾓度计算⽅式:计算原理基于算⼦elliptic_axis。此外,还计算了轮廓上离重⼼最⼤距离的点。如果此点的列坐标⼩于重⼼的列坐标,则elliptic_axis计算得到的⾓度值需要加上π。
⾓度表⽰⽅式:弧度,-π<=Phi<π
8、计算contours 或 polygons的等效椭圆的参数
elliptic_axis_xld(XLD : : : Ra, Rb, Phi)
⾓度计算⽅式:计算原理同算⼦elliptic_axis。需要注意的是输⼊的contours 或 polygons不能⾃相交,如果他们不是闭合轮廓,那么在计算过程中会⾃动闭合,由此可能会产⽣⾃相交,从⽽导致最终的计算结果不准确。如果输⼊的轮廓存在⾃相交,可⽤
elliptic_axis_points_xld算⼦代替。
⾓度表⽰⽅式:弧度,-π/2<Phi<=π/2
9、计算contours 或 polygons的⽅向
orientation_xld(XLD : : : Phi)
⾓度计算⽅式:计算原理同算⼦orientation_region。需要注意的是输⼊的contours 或 polygons不能⾃相交,如果他们不是闭合轮廓,那么在计算过程中会⾃动闭合,由此可能会产⽣⾃相交,从⽽导致最终的计算结果不准确。如果输⼊的轮廓存在⾃相交,可⽤
orientation_points_xld算⼦代替。
⾓度表⽰⽅式:弧度,-π<Phi<=π
总结
计算⾓度时,如果有⽅向性,⾓度范围⼀般是(-π,π)。如果没有⽅向性,⾓度范围⼀般是(-π/2,π/2)
拟合/测量
*************************测量算⼦*******************************
*画仿射矩形
draw_rectangle2 (3600, Row5, Column4, Phi1, Length1, Length2)
gen_rectangle2 (Rectangle1, Row5, Column4, Phi1, Length1, Length2)
*获取测量句柄
gen_measure_rectangle2 (Row5, Column4, Phi1, Length1, Length2, 512, 512, 'nearest_neighbor', MeasureHandle)
*句柄,平滑参数,灰度差,极性,选择边缘点,边缘中⼼y,x坐标,幅度,距离
measure_pos (Image, MeasureHandle, 6.1, 65, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distanc
e)
gen_cross_contour_xld (Cross, RowEdge, ColumnEdge, 6, Phi1)
close_measure (MeasureHandle)
*************************图像--区域--轮廓************************
*区域转轮廓
gen_contour_region_xld (SelectedRegions, Contours, 'border')
*轮廓点坐标
get_contour_xld (Contours, Row, Col)
gen_cross_contour_xld (Cross1, Row, Col, 6, Phi1)
*轮廓拟合圆
fit_circle_contour_xld (Contours, 'algebraic', -1, 0, 0, 3, 2, Row3, Column, Radius, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row3, Column, Radius, 0, 6.28318, 'positive', 1)
*轮廓拟合椭圆或椭圆弧
fit_ellipse_contour_xld (Contours, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row4, Column3, Phi, Radius1, Radius2, StartPhi1,
EndPhi1, PointOrder1)
gen_ellipse_contour_xld (ContEllipse, Row4, Column3, Phi, Radius1, Radius2, 0, 6.28318, 'positive', 1.5)
**************************图像--轮廓**************************
*提取亚像素精度边缘轮廓
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
*筛选出指定轮廓
select_contours_xld (Edges, SelectedContours, 'contour_length', 0, 50, -0.5, 0.5)
dev_set_color ('green')
*拟合直线
fit_line_contour_xld (SelectedContours, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
disp_line (3600, RowBegin, ColBegin, RowEnd, ColEnd)
****************************拟合矩形****************************
*⽣成感兴趣的区域
read_image (Image, 'fabrik')
draw_rectangle1 (3600, Row11, Column11, Row2, Column2)
gen_rectangle1 (Rectangle, Row11, Column11, Row2, Column2)
reduce_domain (Image, Rectangle, ImageReduced)
*提取轮廓,拟合矩形
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
select_contours_xld (Edges, SelectedContours, 'contour_length', 80, 800, -0.5, 0.5)
fit_rectangle2_contour_xld (SelectedContours, 'regression', -1, 0, 0, 3, 2, Row1, Column1, Phi1, Length11, Length21, PointOrder)
gen_rectangle2 (Rectangle1, Row1, Column1, Phi1, Length11, Length21)
***********************************计算垂⾜、夹⾓***************************************
read_image (Image, 'fabrik')
draw_rectangle1 (3600, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (Image, Rectangle, ImageReduced)
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
sort_contours_xld (Edges, SortedContours, 'upper_left', 'true', 'row')
*取轮廓上的点
select_obj (SortedContours, ObjectSelected, 2)
get_contour_xld (ObjectSelected, Row, Col)
*取轮廓上的线
select_obj (SortedContours, ObjectSelected1, 10)
fit_line_contour_xld (ObjectSelected1, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist) *计算点到线的垂⾜
projection_pl (Row[0],Col[0],RowBegin, ColBegin, RowEnd, ColEnd ,RowProj, ColProj)
*显⽰点、直线、垂⾜、垂线
gen_cross_contour_xld (Cross,Row[0],Col[0], 6, 0.785398)
disp_line (3600, RowBegin, ColBegin, RowEnd, ColEnd)
gen_cross_contour_xld (Cross1,RowProj, ColProj, 6, 0.785398)
disp_line (3600, Row[0],Col[0],RowProj, ColProj)
*计算两条直线的夹⾓
angle_ll ( RowBegin, ColBegin, RowEnd, ColEnd, Row[0],Col[0],RowProj, ColProj, Angle)
*弧度转⾓度deg,⾓度转弧度rad
Ang:=deg(Angle)
*计算直线和⽔平轴x的夹⾓
拟合直线
angle_lx (RowBegin, ColBegin, RowEnd, ColEnd, Angle1)
Ang1:=deg(Angle1)
angle_lx (Row[0],Col[0],RowProj, ColProj, Angle2)
Ang2:=deg(Angle2)
项⽬案例
halcon学习笔记——实例篇(2)长度和⾓度测量

本文发布于:2024-09-23 17:15:21,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/359541.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:计算   轮廓   直线   平轴   拟合   区域
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议