Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Halcon operator

Shulou Source: shulou.com Published: 2022-06-02 03:42:15 09月25日 Update

This article shows you an example analysis of the Halcon operator, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Read_image (Image,'fabrik')

* draw a rectangle

Draw_rectangle1 (3600, Row1, Column1, Row2, Column2)

Gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)

* reduce the domain of image definition

Reduce_domain (Image, Rectangle, ImageReduced)

* threshold segmenting the parts of interest

Threshold (ImageReduced, Region, 0,65)

* separate areas that are not connected into separate areas

Connection (Region, ConnectedRegions)

* filter the designated area according to the area area

Select_shape (ConnectedRegions, SelectedRegions, 'area',' and', 2500, 5150)

* Measurement operator * *

* draw an affine rectangle

Draw_rectangle2 (3600, Row5, Column4, Phi1, Length2, Length3)

Gen_rectangle2 (Rectangle1, Row5, Column4, Phi1, Length2, Length3)

* get the measurement handle

Gen_measure_rectangle2 (Row5, Column4, Phi1, Length2, Length3, 512,512, 'nearest_neighbor', MeasureHandle)

* handle, smoothing parameters, grayscale difference, polarity, selection of edge points, edge center y _ (th) x coordinates, amplitude, distance

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)

* Image-region-outline *

* region turning contours

Gen_contour_region_xld (SelectedRegions, Contours, 'border')

* outline point coordinates

Get_contour_xld (Contours, Row, Col)

Gen_cross_contour_xld (Cross1, Row, Col, 6, Phi1)

* outline fitting circle

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)

* profile fitting ellipse or elliptical arc

Fit_ellipse_contour_xld (Contours, 'fitzgibbon',-1,0,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)

* * Image-outline * *

* extract sub-pixel precision edge contours

Edges_sub_pix (ImageReduced, Edges, 'canny', 1,20,40)

* filter out the specified profile

Select_contours_xld (Edges, SelectedContours, 'contour_length', 0,50,-0.5,0.5)

Dev_set_color ('green')

* fit straight line

Fit_line_contour_xld (SelectedContours, 'tukey',-1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Disp_line (3600, RowBegin, ColBegin, RowEnd, ColEnd)

* * fit rectangle * *

* generate areas of interest

Read_image (Image, 'fabrik')

Draw_rectangle1 (3600, Row11, Column11, Row2, Column2)

Gen_rectangle1 (Rectangle, Row11, Column11, Row2, Column2)

Reduce_domain (Image, Rectangle, ImageReduced)

* extract contours and fit rectangles

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)

* * calculate the vertical foot and the included angle * *

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

* take the points on the outline

Select_obj (SortedContours, ObjectSelected, 2)

Get_contour_xld (ObjectSelected, Row, Col)

* take the line on the outline

Select_obj (SortedContours, ObjectSelected1, 10)

Fit_line_contour_xld (ObjectSelected1, 'tukey',-1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

* calculate the vertical foot from point to line

Projection_pl (Row [0], Col [0], RowBegin, ColBegin, RowEnd, ColEnd, RowProj, ColProj)

* display points, lines, vertical feet, vertical lines

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)

* calculate the angle between two lines

Angle_ll (RowBegin, ColBegin, RowEnd, ColEnd, Row [0], Col [0], RowProj, ColProj, Angle)

* Radian to angle deg, angle to Radian rad

Ang:=deg (Angle)

* calculate the angle between the line and the horizontal axis x

Angle_lx (RowBegin, ColBegin, RowEnd, ColEnd, Angle1)

Ang1:=deg (Angle1)

Angle_lx (Row [0], Col [0], RowProj, ColProj, Angle2)

Ang2:=deg (Angle2)

The above is a sample analysis of the Halcon operator. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Contours regions lines rectangles operators images angles edges examples analysis interests content handles coordinates radians skills ellipses knowledge angles select Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information MySQL Apple macOS