当前位置:网站首页>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
边栏推荐
- How can flinksql calculate the difference between a field before and after update when docking with CDC?
- Chinese and English instructions prosci LAG-3 recombinant protein
- Stack Title: nesting depth of valid parentheses
- Role of virtual machine
- from . onnxruntime_ pybind11_ State Import * noqa ddddocr operation error
- How Oracle backs up indexes
- Pass parent component to child component: props
- MySQL view bin log and recover data
- 选择商品属性弹框从底部弹出动画效果
- Network foundation - header, encapsulation and unpacking
猜你喜欢
Kuboard can't send email and nail alarm problem is solved
How can gyms improve their competitiveness?
Freeswitch dials extension number source code tracking
At the age of 20, I got the ByteDance offer on four sides, and I still can't believe it
Asynchronous components and suspend (in real development)
AVL树的实现
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
Maze games based on JS
Mysql---- import and export & View & Index & execution plan
Jetpack compose is much more than a UI framework~
随机推荐
How to share the same storage among multiple kubernetes clusters
After the promotion, sales volume and flow are both. Is it really easy to relax?
关于数据库数据转移的问题,求各位解答下
$parent (get parent component) and $root (get root component)
Freeswitch dials extension number source code tracking
Multithreading and high concurrency (9) -- other synchronization components of AQS (semaphore, reentrantreadwritelock, exchanger)
Answer to the second stage of the assignment of "information security management and evaluation" of the higher vocational group of the 2018 Jiangsu Vocational College skills competition
From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype
Learning records on July 4, 2022
Lvs+kept (DR mode) learning notes
Several important steps to light up the display
Pass child component to parent component
How can gyms improve their competitiveness?
Readonly read only
Get the city according to IP
Détailler le bleu dans les tâches de traduction automatique
How to model and simulate the target robot [mathematical / control significance]
点亮显示屏的几个重要步骤
Matlab tips (29) polynomial fitting plotfit
Unity C function notes