当前位置:网站首页>Project practice five fitting straight lines to obtain the center line

Project practice five fitting straight lines to obtain the center line

2022-07-07 07:16:00 Σίσυφος one thousand and nine hundred

One 、 brief introduction

        The most common fitting in projects is generally straight line fitting and circle fitting , But I was self-taught at first halcon When I see something similar to a straight line, I always fit it directly , As soon as you see something similar to a circle, you can directly fit the circle , But we should have many taboos when doing projects , There are many things to consider , So let the algorithm have stronger compatibility , Now let's see how to fit this fitting line :

1、 Pass in a picture , And a ROI

2、 Use a two-dimensional caliper to find the point of the fitting line ( This is an important step )

3、 Fit the circle from the point in the second step , But we will set the minimum distance from a point to a straight line , Use this distance to judge the fitting superiority of the straight line , Delete some to jump point , Prevent some individual points from causing the fitting line to be unsatisfactory

4、 Output

We can get one from the above Or multiple straight lines , If it is to find the center line of two straight lines , How to ask ?

1 、 First pass in two midlines

2、 Judge the angle of these two straight lines and whether they intersect

3、 If it intersects , Find on a straight line ( The endpoint of the line segment ) Projection point on another line , Take the midpoint directly , Similarly, find the projection of another endpoint , Finding the midpoint , The central line is connected

4、 If there is an intersection , Then this is more complicated , First we need to calculate two endpoints ( The end point of the straight line ) To 2 The distance from point to point calculated in d1 d2

5、 And then to 2 The intersection of ( hypothesis r,c)r,c,d1 as well as r,c,d2 A circle , Then calculate the intersection of another line and the two circles

6、 The two endpoints in the figure above are the two points we want most  

7、 The final output

Two 、 Fit a straight line

Core code : 

        *  Use two-dimensional measurements to find points 
        create_metrology_model (MetrologyHandle)
        * Set the size of the handle model 
        set_metrology_model_image_size (MetrologyHandle, Width, Height)
        add_metrology_object_generic (MetrologyHandle, 'line', [Row1,Col1,Row2,Col2], Len2[Len2Index], RectWidth[RectWidthIndex], Sigma[SigmaIndex], Threshold[ThresholdIndex], [], [], temp)
        *  Set parameters 
        set_metrology_object_param (MetrologyHandle, 'all', ['measure_transition','num_measures','measure_select'], [Transtion[TransitionIndex], Count[CountIndex], Select[SelectIndex]])
     *  set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', Select[SelectIndex])    
        * Using parameter 
        apply_metrology_model (Image, MetrologyHandle)
        *  Get the results 
        get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Rows, Columns)
        gen_cross_contour_xld (Cross1, Rows, Columns, 6, 0.78)
        clear_metrology_model (MetrologyHandle)


      * Fit a straight line 
            fit_line_contour_xld (Contour, 'drop', -1, 0, 5, 2, TempRowBegin, TempColBegin, TempRowEnd, TempColEnd, TempNr, TempNc, TempDist)
             *  Calculate the distance between the fitted line and the point 
            distance_pl (Rows, Columns, TempRowBegin, TempColBegin, TempRowEnd, TempColEnd, Distance)
            tuple_max (Distance, Max)
            *  Are there enough points in the deletion points of the connection to fit 
            *   Delete max/2 The point of 
            if(Max < MinDist[MinDistIndex])
                break
            endif
            *  Delete points that do not conform to the distance from the point to the straight line 
            tuple_less_elem (Distance, Max/2, Less)
            tuple_find (Less, 0, Indices)
            tuple_remove (Rows, Indices, ValidRows)
            tuple_remove (Columns, Indices, ValidCols)

3、 ... and 、 Get the center line

Core code :

  * Find the intersection of a line and a circle 
   gen_circle_contour_xld (ContCircle, Row, Column,  Distance1, 0, 6.28318, 'positive', 1)
   gen_circle_contour_xld (ContCircle2, Row, Column,  Distance2, 0, 6.28318, 'positive', 1)
   intersection_line_circle (line2[0], line2[1], line2[2], line2[3], Row, Column, Distance1, 0, 6.28318, 'positive', Row1, Column1)
   intersection_line_circle (line2[0], line2[1], line2[2], line2[3], Row, Column, Distance2, 0, 6.28318, 'positive', Row2, Column2)
   *  Show intersections 

原网站

版权声明
本文为[Σίσυφος one thousand and nine hundred]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070203487631.html