您好,登錄后才能下訂單哦!
本篇文章為大家展示了Halcon算子的示例分析,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
read_image (Image,'fabrik')
*畫矩形
draw_rectangle1 (3600, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
*縮減圖像定義域
reduce_domain (Image, Rectangle, ImageReduced)
*閾值分割出感興趣的部分
threshold (ImageReduced, Region, 0, 65)
*將不相互連接的區域分開為單獨區域
connection (Region, ConnectedRegions)
*根據區域面積篩選出指定區域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 2500, 5150)
*************************測量算子*******************************
*畫仿射矩形
draw_rectangle2 (3600, Row5, Column4, Phi1, Length2, Length3)
gen_rectangle2 (Rectangle1, Row5, Column4, Phi1, Length2, Length3)
*獲取測量句柄
gen_measure_rectangle2 (Row5, Column4, Phi1, Length2, Length3, 512, 512, 'nearest_neighbor', MeasureHandle)
*句柄,平滑參數,灰度差,極性,選擇邊緣點,邊緣中心y,x坐標,幅度,距離
measure_pos (Image, MeasureHandle, 6.1, 65, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
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, Length21, Length31, PointOrder)
gen_rectangle2 (Rectangle1, Row1, Column1, Phi1, Length21, Length31)
***********************************計算垂足、夾角***************************************
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算子的示例分析,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。