当前位置:网站首页>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 边栏推荐
- [Luogu p1971] rabbit and egg game (bipartite game)
- readonly 只读
- Abnova membrane protein lipoprotein technology and category display
- Leetcode t1165: log analysis
- 弹性布局(一)
- Bindingexception exception (error reporting) processing
- LC 面试题 02.07. 链表相交 & LC142. 环形链表II
- 关于数据库数据转移的问题,求各位解答下
- Reflection (II)
- 【mysqld】Can't create/write to file
猜你喜欢

How to share the same storage among multiple kubernetes clusters

Communication between non parent and child components

計算機服務中缺失MySQL服務

父组件传递给子组件:Props

Nesting and splitting of components

$refs: get the element object or sub component instance in the component:

组件的嵌套和拆分

Freeswitch dials extension number source code tracking

虚拟机的作用

弹性布局(二)
随机推荐
AVL树的实现
Pass child component to parent component
Reflection (II)
How Oracle backs up indexes
Mysql---- import and export & View & Index & execution plan
Basic introduction of JWT
JDBC database connection pool usage problem
Config distributed configuration center
Sqlserver multithreaded query problem
Le Service MySQL manque dans le service informatique
Select the product attribute pop-up box to pop up the animation effect from the bottom
LC 面试题 02.07. 链表相交 & LC142. 环形链表II
Abnova circulating tumor DNA whole blood isolation, genomic DNA extraction and analysis
Unity3d learning notes
How does an enterprise manage data? Share the experience summary of four aspects of data governance
How DHCP router works
from . onnxruntime_ pybind11_ State Import * noqa ddddocr operation error
【JDBC以及内部类的讲解】
Asynchronous components and suspend (in real development)
请问 flinksql对接cdc时 如何实现计算某个字段update前后的差异 ?