当前位置:网站首页>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
边栏推荐
- ViewModelProvider. Of obsolete solution
- 詳解機器翻譯任務中的BLEU
- From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype
- Mysql---- import and export & View & Index & execution plan
- Asynchronous components and suspend (in real development)
- js小练习----分时提醒问候、表单密码显示隐藏效果、文本框焦点事件、关闭广告
- Sword finger offer high quality code
- Big coffee gathering | nextarch foundation cloud development meetup is coming
- Academic report series (VI) - autonomous driving on the journey to full autonomy
- 关于数据库数据转移的问题,求各位解答下
猜你喜欢
Nesting and splitting of components
Matlab tips (30) nonlinear fitting lsqcurefit
弹性布局(一)
Release notes of JMeter version 5.5
LC interview question 02.07 Linked list intersection & lc142 Circular linked list II
[noi simulation] regional division (conclusion, structure)
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
关于数据库数据转移的问题,求各位解答下
非父子组件的通信
$parent(获取父组件) 和 $root(获取根组件)
随机推荐
Please answer the questions about database data transfer
from . onnxruntime_ pybind11_ State Import * noqa ddddocr operation error
Network foundation - header, encapsulation and unpacking
Basic introduction of JWT
oracle如何备份索引
弹性布局(一)
Matlab tips (29) polynomial fitting plotfit
MySQL binlog related commands
Apache AB stress test
Sword finger offer high quality code
【JDBC以及内部类的讲解】
Use of completable future
Pass child component to parent component
toRefs API 与 toRef Api
Communication of components
Détailler le bleu dans les tâches de traduction automatique
CompletableFuture使用详解
The startup of MySQL installed in RPM mode of Linux system failed
Software acceptance test
Under what circumstances should we consider sub database and sub table