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, 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, 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, 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)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章