当前位置:网站首页>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
边栏推荐
- MySQL binlog related commands
- Libcurl returns curlcode description
- Détailler le bleu dans les tâches de traduction automatique
- mips uclibc 交叉编译ffmpeg,支持 G711A 编解码
- Mobx knowledge point collection case (quick start)
- LC interview question 02.07 Linked list intersection & lc142 Circular linked list II
- readonly 只读
- 抽丝剥茧C语言(高阶)指针的进阶
- 请教一个问题,flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取全量数据
- Please ask a question, flick Oracle CDC, read a table without update operation, and repeatedly read the full amount of data every ten seconds
猜你喜欢
Take you to brush (niuke.com) C language hundred questions (the first day)
How can clothing stores make profits?
AVL树的实现
Freeswitch dials extension number source code tracking
计算机服务中缺失MySQL服务
.net core 访问不常见的静态文件类型(MIME 类型)
Reflection (II)
Special behavior of main function in import statement
SolidWorks GB Library (steel profile library, including aluminum profile, aluminum tube and other structures) installation and use tutorial (generating aluminum profile as an example)
异步组件和Suspense(真实开发中)
随机推荐
请问 flinksql对接cdc时 如何实现计算某个字段update前后的差异 ?
LC interview question 02.07 Linked list intersection & lc142 Circular linked list II
Libcurl returns curlcode description
Several important steps to light up the display
Pass child component to parent component
計算機服務中缺失MySQL服務
【mysqld】Can't create/write to file
Under what circumstances should we consider sub database and sub table
[noi simulation] regional division (conclusion, structure)
How to share the same storage among multiple kubernetes clusters
MySQL service is missing from computer service
子组件传递给父组件
Multidisciplinary integration
Communication between non parent and child components
Advantages of using net core / why
Matlab tips (29) polynomial fitting plotfit
Basic introduction of JWT
How can flinksql calculate the difference between a field before and after update when docking with CDC?
组件的嵌套和拆分
Apache AB stress test