Halcon 拟合

文章目录

算子

二值化算子 (二值化后获取的都是区域)

二值化算子

clip_region_rel 剪切区域

 clip_region_rel(Region : RegionClipped : Top, Bottom, Left, Right : )
 Region是输入区域;
 RegioonClipped是减掉后的输出区域;
 Top, 顶端
 Bottom,底端
 Left,左边
 Right右边

在这里插入图片描述

edges_sub_pix 提取亚像素边缘

 edges_sub_pix(Image : Edges : Filter, Alpha, Low, High : )*提取亚像素精密边缘轮廓

 Filter :过滤算法
 Filter  = 'canny'刚好相反,alpha值越大,轮廓细节就越少(可能有一部分轮廓消失)
 alpha:指定值越小,平滑越强大,会减少边缘细节。

 Low和High:
           使用灰度直方图计算两个阀值,凡是像素灰度值大于高阀值的一定是轮廓; 凡是小于低阀值的一定不是轮廓;
            如果检测像素灰度值大于低阀值但又小于高阀值,那就要看这个像素的邻接像素中有没有超过高阀值的边缘像素:如果有的话那么它就是轮廓边缘了,否则他就不是轮廓边缘;
           

lines_gauss 检测线条算子

lines_gauss(Image : Lines : Sigma, Low, High, LightDark, ExtractWidth, LineModel, CompleteJunctions : )
Image (input_object) :输入图像
Lines (output_object) :检测线条(XLD)
Sigma (input_control) :高斯滤波值
Low (input_control) :滞后阈值分割的低阈值
High (input_control) :滞后阈值分割的高阈值
LightDark (input_control) :提取线条类型( ‘dark’,‘light’)
ExtractWidth (input_control) :是否提取线宽(‘false’,‘true’)
LineModel (input_control) :用来调整线条位置和宽度的线模型(‘bar-shaped’, ‘gaussian’, ‘none’, ‘parabolic’)
CompleteJunctions (input_control) :在断连的部分是否添加节点使线条连续(‘false’, ‘true’)

clip_contours_xld 亚像素边缘分割

clip_contours_xld ( Contours : ClippedContours : Row1, Column1,Row2, Column2 : )
Contours :待分割的轮廓
ClippedContours :分割后的轮廓
 Row1, Column1,Row2, Column2: 轮廓的左上角坐标和右下角坐标

segment_contours_xld 亚像素边缘分割

segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
Edges:待分割的轮廓
ContoursSplit:分割后的轮廓
'lines_circles':分割模式,分割出线段、类圆
5:平滑轮廓系数
4:最大线距
2:最小线距

union_collinear_contours_xld 边缘联合共线

union_collinear_contours_xld(Contours : UnionContours : MaxDistAbs, MaxDistRel, MaxShift, MaxAngle, Mode : )
Contours (input_object) :输入XLD轮廓
UnionContours (output_object) :合并后输出轮廓
MaxDistAbs (input_control) :沿参考轮廓的回归线测量两个轮廓之间的最大间隙长度(间隙在参考轮廓拟合直线上的投影)。
MaxDistRel (input_control) :间隙在参考轮廓拟合直线上的投影长度与参考轮廓长度的比值上限(见下面详解)
MaxShift (input_control) :第二个轮廓与参考轮廓拟合直线的最大距离
MaxAngle (input_control) :两个轮廓拟合直线的角度( 0.0 ≤ MaxAngle ≤ 0.7853981633945度))
Mode (input_control) :定义轮廓属性处理的模式,即,是否保留或丢弃轮廓属性

union_adjacent_contours_xld 临近联合,将端点距离很近的轮廓连接起来

union_adjacent_contours_xld(Contours : UnionContours : MaxDistAbs, MaxDistRel, Mode : )
Contours (input_object) :输入轮廓
UnionContours (output_object) :合并后输出轮廓
MaxDistAbs (input_control) :两个轮廓端点间的最小距离控制参数
MaxDistRel (input_control) :两个轮廓端点间的最小距离与最长轮廓长度的比值控制参数
Mode (input_control) :定义轮廓属性处理的模式,即,是否保留或丢弃轮廓属性

union_cocircular_contours_xld 联合圆

Contours:输入的共圆轮廓XLD对象。
CenterRow:共圆的圆心的行坐标。
CenterColumn:共圆的圆心的列坐标。
Radius:共圆的半径。
StartPhi:共圆曲线的起始角度。
EndPhi:共圆曲线的结束角度。


regress_contours_xld 求具有回归属性的轮廓

regress_contours_xld(Contours : RegressContours : Mode, Iterations : )
    Contours:这是输入参数,表示将进行回归的 XLD 轮廓。
    RegressContours:这是输出参数,将存储回归后的结果轮廓。
    Mode:此参数确定要执行的回归类型。根据所需的回归方法可以采用不同的值,如“algebraic”(代数)、“directional”(方向)、“elliptic”(椭圆)等。
    Iterations:此参数指定在回归过程中执行的迭代次数。它有助于改善回归结果。

sort_contours_xld 轮廓区域排序

sort_contours_xld(Contours : SortedContours : SortMode, Order, RowOrCol : )

示例:sort_contours_xld (ContoursSplit, SortedContours, 'upper_left', 'true', 'column')

ContoursSplit(输入对象):输入包含多个轮廓的对象

SortedContours(输出对象):输出排序轮廓对象

'upper_left'(输入控制参数1):排序方法

'true'(输入控制参数2):升序true或者是降序false

'column'(输入控制参数3):按照行或者列排序

get_contour_global_attrib_xld 亚像素拟合,自动判断拟合对象算子(直线,椭圆,圆)

get_contour_global_attrib_xld (ObjectSelected输入轮廓, 
								'cont_approx'判断算法, 
								Attrib输出结果)

fit_circle_contour_xld 拟合圆算子

fit_circle_contour_xld(Contours,输入轮廓
						Algorithm,拟合算法,如最小二乘法
						MaxNumPoints,拟合时采用轮廓最多的点数,-1表示全部参与
						MaxClosureDist,是指Maximum distance between the end points of a contour to be considered as 'closed'用来区分拟合成圆还是圆弧 ,就是要拟合的最后一个点和被认为把轮廓封闭的点,这两个点距离
						ClippingEndPoints,拟合时忽略轮廓开始和结束点的数量
						Iterations,拟合迭代的最大次数
						ClippingFactor,离群值的裁剪因子,越小离群值越多
						Row, 输出圆的坐标
						Column,
						Radius,输出圆半径
						StartPhi,输出圆开始角度
						EndPhi,输出圆终止角度
						PointOrder边界点正反向)

gen_circle_contour_xld 产生亚像素圆拟合图像

gen_circle_contour_xld(:ContCircle:Row,Column,Radius,StartPhi,EndPhi,PointOrder,Resolution)
ContCircle(output_object)xld_cont(-array)→对象
产生的轮廓。
Row(input_control)circle.center.y(-array)→(real)
圆心或圆弧的中心的行坐标。
默认值:200.0
Column (input_control)circle.center.x(-array)→(真实)
圆心或圆弧的圆柱坐标。
默认值:200.0
Radius (input_control)circle.radius(-array)→(真实)
圆弧或圆弧的半径。
默认值:100.0
限制:半径> 0
StartPhi(input_control)real(-array)→(真实)
圆的起点或圆弧[rad]的角度。
默认值:0.0
EndPhi(input_control)real(-array)→(真实)
圆弧或圆弧[rad]的终点角度。
默认值:6.28318
PointOrder(input_control)string(-array)→(string)
沿圆或圆弧的点顺序。
默认值:‘正面’
价值清单:‘负面’,‘正面’
Resolution(input_control)真实→(真实)
相邻轮廓点之间的距离。
默认值:1.0
限制:分辨率> = 0.00001

fit_line_contour_xld 拟合成直线

fit_line_contour_xld(Contours : : Algorithm, MaxNumPoints, ClippingEndPoints, Iterations, ClippingFactor : RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)

Contours (input_object) :输入的XLD轮廓
Algorithm (input_control):直线拟合算法( ‘drop’, ‘gauss’, ‘huber’, ‘regression’, ‘tukey’)
MaxNumPoints (input_control):参与拟合直线的最大轮廓点数(设置-1代表所有点参与计算;最小值要大于等于2,因为至少两点才能确认一条直线)
ClippingEndPoints (input_control) :拟合直线时,需要忽略轮廓起始处点个数。(一个XLD轮廓会被线分割成很多个小轮廓)
Iterations (input_control) :最大迭代次数。(不适用于’regression’)
ClippingFactor (input_control):剔除异常值因子。(算法 ‘huber’ 、‘drop’ 设置1.0,'tukey’设置2.0RowBegin (output_control) :拟合后的线段起始点行坐标
ColBegin (output_control) :拟合后的线段起始点列坐标
RowEnd (output_control) :拟合后的线段终点点行坐标
ColEnd (output_control) :拟合后的线段终点点列坐标
Nr (output_control) :直线方程法线式x相乘系数
Nc (output_control) :直线方程法线式y相乘系数
Dist (output_control) :坐标系原点到线段的距离

gen_contour_polygon_xld 产生多边形亚像素轮廓

gen_contour_polygon_xld ()从一个多边形生成一个XLD轮廓(以元组的形式给出)。

参数:
Contour (output_object) :产生的轮廓。

Row(input_control):多边形的行坐标。

默认值:[0,1222]

建议值:012345102050100200500

Col(input_control):多边形的列坐标。

默认值:[0,0,0,1,2)

建议值:012345102050100200500

XLD转 region (图像进行二值化的都是区域)
gen_region_contour_xld (ContoursUnion, Region, ‘filled’)
region 转 XLD
gen_contour_region_xld (SelectedRegions, Contours, ‘border’)

shape_trans 变换区域的形状

convex:凸包性

ellipse:与输入区域有相同的矩和区域的椭圆

outer_circle:最小外接圆

inner_circle:最大内接圆

rectangle1:平行于坐标轴的最小外接矩形

rectangle2:最小外接矩形

inner_rectangle1:平行于坐标轴的最大内接矩形

inner_rectangle2:输入区域的骨架点拥有同输入区域的重心点最小的距离

shape_trans 示例

更多xld算子

更多区域算子

Blob 分析案例

Blob 分析案例

预处理图像增强降噪

图像降噪

图像增强

Halcon 基于圆的拟合

在这里插入图片描述

* 
* The edges in the image are segmented into lines and circles.
* For the edges that are part of a circle, the circle parameters
* are estimated and the resulting circle is displayed.
read_image (Image, 'double_circle')
* 
* Init window
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* 
* Segment a region containing the edges
* 快速二值化 二值化得到的都是区域
fast_threshold (Image, Region, 0, 120, 7)
* 对区域求轮廓  内边界'inner'
boundary (Region, RegionBorder, 'inner')
* 裁剪区域
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
* 膨胀
dilation_circle (RegionClipped, RegionDilation, 2.5)
* 裁剪区域
reduce_domain (Image, RegionDilation, ImageReduced)
* 
* In the subdomain of the image containing the edges,
* extract subpixel precise edges.
* 亚像素边缘提取
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
*  亚像素分割
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
count_obj (ContoursSplit, Number)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for I := 1 to Number by 1
    * 选择第一个轮廓
    select_obj (ContoursSplit, ObjectSelected, I)
    * 拟合
    get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
    * Fit a circle to the line segment that are arcs of a circle
    if (Attrib > 0)
        * 形成一个圆的拟合
        fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
        * 产生拟合图像
        gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
        dev_display (ContCircle)
    endif
endfor
dev_set_colored (12)
dev_set_line_width (3)
dev_display (ContoursSplit)

在这里插入图片描述

Halcon 拟合成直线和圆计算距离

在这里插入图片描述

* measure_metal_part.hdev: inspects metal part by fitting lines and circles
* 
dev_close_window ()
dev_update_window ('off')
* ****
* step: acquire image
* ****
read_image (Image, 'metal-parts/metal-parts-01')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Width, WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: create contours
* ****
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 40, 90)
dev_display (Edges)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: process contours
* ****
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 6, 4, 4)
sort_contours_xld (ContoursSplit, SortedContours, 'upper_left', 'true', 'column')
dev_clear_window ()
dev_set_colored (12)
dev_display (SortedContours)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: perform fitting
* ****
ROI := [115,225,395,535]
dev_open_window (0, round(Width / 2), (ROI[3] - ROI[1]) * 2, (ROI[2] - ROI[0]) * 2, 'black', WindowHandleZoom)
dev_set_part (round(ROI[0]), round(ROI[1]), round(ROI[2]), round(ROI[3]))
set_display_font (WindowHandleZoom, 14, 'mono', 'true', 'false')
count_obj (SortedContours, NumSegments)
dev_display (Image)
NumCircles := 0
NumLines := 0
for i := 1 to NumSegments by 1
    select_obj (SortedContours, SingleSegment, i)
    get_contour_global_attrib_xld (SingleSegment, 'cont_approx', Attrib)
    if (Attrib == 1)
        NumCircles := NumCircles + 1
        fit_circle_contour_xld (SingleSegment, 'atukey', -1, 2, 0, 5, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
        gen_ellipse_contour_xld (ContEllipse, Row, Column, 0, Radius, Radius, 0, rad(360), 'positive', 1.0)
        dev_set_color ('white')
        dev_display (ContEllipse)
        set_tposition (WindowHandleZoom, Row - Radius - 10, Column)
        write_string (WindowHandleZoom, 'C' + NumCircles)
        ResultText := 'C' + NumCircles + ': radius = ' + Radius
    else
        NumLines := NumLines + 1
        fit_line_contour_xld (SingleSegment, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
        gen_contour_polygon_xld (Line, [RowBegin,RowEnd], [ColBegin,ColEnd])
        dev_set_color ('yellow')
        dev_display (Line)
        * 计算距离
        distance_pp (RowBegin, ColBegin, RowEnd, ColEnd, Length)
        * 设置显示位置
        set_tposition (WindowHandleZoom, (RowBegin + RowEnd) / 2 - Nr * 10, (ColBegin + ColEnd) / 2)
        write_string (WindowHandleZoom, 'L' + NumLines)
        ResultText := 'L' + NumLines + ': length = ' + Length
    endif
    set_tposition (WindowHandleZoom, 275 + i * 10, 230)
    write_string (WindowHandleZoom, ResultText)
endfor
disp_continue_message (WindowID, 'black', 'true')
stop ()
dev_set_window (WindowHandleZoom)
dev_close_window ()
dev_clear_window ()

在这里插入图片描述

Halcon 共线联合案例

在这里插入图片描述

* close_contour_gaps.hdev: closes gaps in extracted straight contours
* 
dev_close_window ()
dev_update_window ('off')
* ****
* step: create synthetic image
* ****
gen_rectangle1 (Rectangle, 30, 20, 100, 100)
* 产生一个二值区域 
region_to_bin (Rectangle, BinImage, 130, 100, 120, 130)
* 矩形区域裁剪
rectangle1_domain (BinImage, ImageReduced, 20, 48, 40, 52)
* 产生均值图像,让图像变得平滑
mean_image (ImageReduced, SmoothedImage, 15, 15)
* 绘制一个灰度图像
paint_gray (SmoothedImage, BinImage, Image)
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowID)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
stop ()
* ****
* step: create contours
* ****
rectangle1_domain (Image, ImageReduced, 5, 5, 125, 115)
* 边界提取
edges_sub_pix (ImageReduced, Edges, 'lanser2', 1.1, 22, 30)
dev_display (Image)
dev_display (Edges)
stop ()
* ****
* step: process contours
* ****
* 亚像素图像分割
segment_contours_xld (Edges, LineSegments, 'lines', 5, 4, 2)
* 计算亚像素轮廓的回归参数
regress_contours_xld (LineSegments, RegressContours, 'no', 1)
* 共线联合轮廓
union_collinear_contours_xld (RegressContours, UnionContours, 10, 1, 2, 0.1, 'attr_keep')
* 亚像素轮廓排序
sort_contours_xld (UnionContours, SortedContours, 'upper_left', 'true', 'column')
dev_display (Image)
colored_display (SortedContours, ['yellow','white','white','yellow'])
dev_update_window ('on')

在这里插入图片描述

Halcon 拟合动画案例

在这里插入图片描述

* This example demonstrates how to use the operator
* union_cotangential_contours_xld.
* Therefore, the operator is applied to a set of synthetic
* contours with different parameter sets.
* 
* Part I
* 
* Test the following parameters:
* - FitClippingLength
* - FitLength
* - MaxTangAngle
* 
* Initialization
get_system ('flush_graphic', FlushGraphic)
* 
* Default parameters
FitClippingLength := 0
FitLength := 30
MaxTangAngle := rad(45)
MaxDist := 25
MaxDistPerp := 10
MaxOverlap := 2
* 
RowOffsets := [25,25,240,240]
ColumnOffsets := [0,256,0,256]
* 
gen_test_contour (ContourConcat1, RowOffsets[0], ColumnOffsets[0])
gen_test_contour (ContourConcat2, RowOffsets[1], ColumnOffsets[1])
gen_test_contour (ContourConcat3, RowOffsets[2], ColumnOffsets[2])
gen_test_contour (ContourConcat4, RowOffsets[3], ColumnOffsets[3])
* 
* Display original contours
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_set_part (0, 0, 511, 511)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_clear_window ()
dev_set_line_width (3)
dev_set_colored (12)
dev_display (ContourConcat1)
dev_display (ContourConcat2)
dev_display (ContourConcat3)
dev_display (ContourConcat4)
Message := 'This example shows the effect of'
Message[1] := 'union_cotangential_contours_xld'
Message[2] := 'with different parameter sets'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'Before', 'window', 12, 420, 'white', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Test values
TestFitClippingLength := 10
TestFitLength := 5
TestMaxTangAngle := rad(135)
* 
* Apply different parameter configurations
union_cotangential_contours_xld (ContourConcat1, UnionContours1, FitClippingLength, FitLength, MaxTangAngle, MaxDist, MaxDistPerp, MaxOverlap, 'attr_forget')
union_cotangential_contours_xld (ContourConcat2, UnionContours2, TestFitClippingLength, FitLength, MaxTangAngle, MaxDist, MaxDistPerp, MaxOverlap, 'attr_forget')
union_cotangential_contours_xld (ContourConcat3, UnionContours3, FitClippingLength, TestFitLength, MaxTangAngle, MaxDist, MaxDistPerp, MaxOverlap, 'attr_forget')
union_cotangential_contours_xld (ContourConcat4, UnionContours4, FitClippingLength, FitLength, TestMaxTangAngle, MaxDist, MaxDistPerp, MaxOverlap, 'attr_forget')
* 
* Display results
dev_clear_window ()
dev_set_line_width (5)
dev_display (UnionContours1)
dev_display (UnionContours2)
dev_display (UnionContours3)
dev_display (UnionContours4)
dev_set_line_width (1)
dev_set_color ('white')
dev_display (ContourConcat1)
dev_display (ContourConcat2)
dev_display (ContourConcat3)
dev_display (ContourConcat4)
Message[0] := 'Results of'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'After', 'window', 12, 420, 'white', 'false')
Text := 'Default parameters:\nFitClippingLength = 0\nFitLength = 30\nMaxTangAngle = rad(45)'
Text[1] := 'Clip endpoints\nFitClippingLength = 10'
Text[2] := 'Fit small end pieces\nFitLength = 5'
Text[3] := 'Allow large angles\nMaxTangAngle = rad(135)'
disp_message (WindowHandle, Text[0], 'window', 200 + RowOffsets[0], 20 + ColumnOffsets[0], 'white', 'false')
disp_message (WindowHandle, Text[1], 'window', 200 + RowOffsets[1], 20 + ColumnOffsets[1], 'white', 'false')
disp_message (WindowHandle, Text[2], 'window', 200 + RowOffsets[2], 20 + ColumnOffsets[2], 'white', 'false')
disp_message (WindowHandle, Text[3], 'window', 200 + RowOffsets[3], 20 + ColumnOffsets[3], 'white', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Part II
* 
* Test the following parameters:
* - MaxDist
* - MaxDistPerp
* - MaxOverlap
* - MaxTangAngle
* 
* Test values
TestMaxDist := 10
TestMaxDistPerp := 10
TestMaxOverlap := 10
TestMaxTangAngle := rad(60)
* 
* Create and display test contours
Row := [200,200,200]
Column := [100,250,400]
Delay := 0.1
gen_empty_obj (FixedContours)
for I := 0 to |Row| - 1 by 1
    gen_ellipse_contour_xld (ContEllipse, Row[I], Column[I], rad(90), 100, 50, 0, rad(90), 'positive', 1.5)
    concat_obj (FixedContours, ContEllipse, FixedContours)
endfor
gen_ellipse_contour_xld (Contour1, Row[0] - 125, Column[0] + 10, rad(270), 25, 35, 0, rad(90), 'positive', 1.5)
gen_ellipse_contour_xld (Contour2, Row[1] - 75, Column[1] + 10, rad(0), 35, 25, 0, rad(90), 'positive', 1.5)
gen_contour_nurbs_xld (Contour3, [100,100,100,100], Column[2] + [0,10,20,30] + 10, 'auto', 'auto', 3, 1, 5)
concat_obj (Contour1, Contour2, ContoursConcat)
concat_obj (ContoursConcat, Contour3, ContoursConcat)
concat_obj (ContoursConcat, FixedContours, ContoursConcat)
Title := 'Test different parameters of\nunion_cotangential_contours_xld'
Text := ''
dev_display_results (ContoursConcat, ContoursConcat, WindowHandle, Title, Text)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Test setting for MaxDist
Title := 'Test influence of MaxDist'
DistY := 0
for DistX := 20 to -10 by -1
    * Modify test contours
    gen_ellipse_contour_xld (Contour1, Row[0] - 125 + DistY, Column[0] + DistX, rad(270), 25, 35, 0, rad(90), 'positive', 1.5)
    gen_ellipse_contour_xld (Contour2, Row[1] - 75 + DistY, Column[1] + DistX, rad(0), 35, 25, 0, rad(90), 'positive', 1.5)
    gen_contour_nurbs_xld (Contour3, [100,100,100,100] + DistY, Column[2] + [0,10,20,30] + DistX, 'auto', 'auto', 3, 1, 5)
    concat_obj (Contour1, Contour2, ContoursConcat)
    concat_obj (ContoursConcat, Contour3, ContoursConcat)
    concat_obj (ContoursConcat, FixedContours, ContoursConcat)
    * Try to unify contours
    union_cotangential_contours_xld (ContoursConcat, UnionContours, FitClippingLength, FitLength, MaxTangAngle, TestMaxDist, MaxDistPerp, MaxOverlap, 'attr_forget')
    * Display results
    Text := 'MaxDist = ' + TestMaxDist
    dev_display_results (UnionContours, ContoursConcat, WindowHandle, Title, Text)
    wait_seconds (Delay)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Test setting for MaxDistPerp
Title := 'Test influence of MaxDistPerp'
DistX := 5
for DistY := -20 to 20 by 1
    * Modify test contours
    gen_ellipse_contour_xld (Contour1, Row[0] - 125 + DistY, Column[0] + DistX, rad(270), 25, 35, 0, rad(90), 'positive', 1.5)
    gen_ellipse_contour_xld (Contour2, Row[1] - 75 + DistY, Column[1] + DistX, rad(0), 35, 25, 0, rad(90), 'positive', 1.5)
    gen_contour_nurbs_xld (Contour3, [100,100,100,100] + DistY, Column[2] + [0,10,20,30] + DistX, 'auto', 'auto', 3, 1, 5)
    concat_obj (Contour1, Contour2, ContoursConcat)
    concat_obj (ContoursConcat, Contour3, ContoursConcat)
    concat_obj (ContoursConcat, FixedContours, ContoursConcat)
    * Try to unify contours
    union_cotangential_contours_xld (ContoursConcat, UnionContours, FitClippingLength, FitLength, MaxTangAngle, MaxDist, TestMaxDistPerp, MaxOverlap, 'attr_forget')
    * Display results
    Text := 'MaxDistPerp = ' + TestMaxDistPerp
    dev_display_results (UnionContours, ContoursConcat, WindowHandle, Title, Text)
    wait_seconds (Delay)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Test positive overlap
Title := 'Test influence of positive MaxOverlap'
DistY := -5
for DistX := -15 to 15 by 1
    * Modify test contours
    gen_ellipse_contour_xld (Contour1, Row[0] - 125 + DistY, Column[0] + DistX, rad(270), 25, 35, 0, rad(90), 'positive', 1.5)
    gen_ellipse_contour_xld (Contour2, Row[1] - 75 + DistY, Column[1] + DistX, rad(0), 35, 25, 0, rad(90), 'positive', 1.5)
    gen_contour_nurbs_xld (Contour3, [100,100,100,100] + DistY, Column[2] + [0,10,20,30] + DistX, 'auto', 'auto', 3, 1, 5)
    concat_obj (Contour1, Contour2, ContoursConcat)
    concat_obj (ContoursConcat, Contour3, ContoursConcat)
    concat_obj (ContoursConcat, FixedContours, ContoursConcat)
    * Try to unify contours
    union_cotangential_contours_xld (ContoursConcat, UnionContours, FitClippingLength, FitLength, MaxTangAngle, MaxDist, MaxDistPerp, abs(TestMaxOverlap), 'attr_forget')
    * Display results
    Text := 'MaxOverlap = ' + abs(TestMaxOverlap)
    dev_display_results (UnionContours, ContoursConcat, WindowHandle, Title, Text)
    wait_seconds (Delay)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Test for negative overlap
Title := 'Test influence of negative MaxOverlap'
DistY := -5
for DistX := -15 to 15 by 1
    * Modify test contours
    gen_ellipse_contour_xld (Contour1, Row[0] - 125 + DistY, Column[0] + DistX, rad(270), 25, 35, 0, rad(90), 'positive', 1.5)
    gen_ellipse_contour_xld (Contour2, Row[1] - 75 + DistY, Column[1] + DistX, rad(0), 35, 25, 0, rad(90), 'positive', 1.5)
    gen_contour_nurbs_xld (Contour3, [100,100,100,100] + DistY, Column[2] + [0,10,20,30] + DistX, 'auto', 'auto', 3, 1, 5)
    concat_obj (Contour1, Contour2, ContoursConcat)
    concat_obj (ContoursConcat, Contour3, ContoursConcat)
    concat_obj (ContoursConcat, FixedContours, ContoursConcat)
    * Try to unify contours
    union_cotangential_contours_xld (ContoursConcat, UnionContours, FitClippingLength, FitLength, MaxTangAngle, MaxDist, MaxDistPerp, -abs(TestMaxOverlap), 'attr_forget')
    * Display results
    Text := 'MaxOverlap = -' + abs(TestMaxOverlap)
    dev_display_results (UnionContours, ContoursConcat, WindowHandle, Title, Text)
    wait_seconds (Delay)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Test settings for the angle between two contours
Title := 'Test influence of MaxTangAngle'
DistX := 10
DistY := 0
hom_mat2d_identity (HomMat2DIdentity)
for Phi := 90 to -90 by -1
    * Modify test contours
    gen_ellipse_contour_xld (Contour1, Row[0] - 125 + DistY, Column[0] + DistX, rad(270), 25, 35, 0, rad(90), 'positive', 1.5)
    hom_mat2d_rotate (HomMat2DIdentity, rad(Phi), Row[0] - 100 + DistY, Column[0] + DistX, HomMat2DRotate)
    affine_trans_contour_xld (Contour1, Contour1, HomMat2DRotate)
    gen_ellipse_contour_xld (Contour2, Row[1] - 75 + DistY, Column[1] + DistX, rad(0), 35, 25, 0, rad(90), 'positive', 1.5)
    hom_mat2d_rotate (HomMat2DIdentity, rad(Phi), Row[1] - 100 + DistY, Column[1] + DistX, HomMat2DRotate)
    affine_trans_contour_xld (Contour2, Contour2, HomMat2DRotate)
    gen_contour_nurbs_xld (Contour3, [100,100,100,100] + DistY, Column[2] + [0,10,20,30] + DistX, 'auto', 'auto', 3, 1, 5)
    hom_mat2d_rotate (HomMat2DIdentity, rad(Phi), Row[2] - 100 + DistY, Column[2] + DistX, HomMat2DRotate)
    affine_trans_contour_xld (Contour3, Contour3, HomMat2DRotate)
    concat_obj (Contour1, Contour2, ContoursConcat)
    concat_obj (ContoursConcat, Contour3, ContoursConcat)
    concat_obj (ContoursConcat, FixedContours, ContoursConcat)
    * Try to unify contours
    union_cotangential_contours_xld (ContoursConcat, UnionContours, FitClippingLength, FitLength, TestMaxTangAngle, MaxDist, MaxDistPerp, TestMaxOverlap, 'attr_forget')
    * Display results
    Text := 'MaxTangAngle = rad(' + deg(TestMaxTangAngle) + ')'
    dev_display_results (UnionContours, ContoursConcat, WindowHandle, Title, Text)
    wait_seconds (Delay / 2)
endfor
set_system ('flush_graphic', FlushGraphic)

在这里插入图片描述

Halcon 拟合椭圆

在这里插入图片描述

* Approximation of XLD contours by ellipses or elliptic arcs
* 产生一个空的图像
gen_image_const (Image, 'byte', 400, 400)
dev_set_color ('green')
* 形成一个椭圆
gen_ellipse (Ellipse, 200, 200, rad(30), 150, 120)
paint_region (Ellipse, Image, ImageEllipse, 255, 'fill')
* 亚像素边缘提取
edges_sub_pix (ImageEllipse, EdgesComplete, 'mderiche2', 0.5, 20, 40)
* First, the easy case:
* 拟合椭圆
fit_ellipse_contour_xld (EdgesComplete, 'fitzgibbon', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
* Now simulate a fragmented ellipse:
* 产生亚像素轮廓
gen_ellipse_contour_xld (ContEllipse, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, 1.5)
gen_rectangle2 (Rectangle1, 200, 200, rad(30), 150, 2)
gen_rectangle2 (Rectangle2, 200, 200, rad(120), 150, 2)
union2 (Rectangle1, Rectangle2, Cross)
* 求区域的补给
complement (Cross, CrossComplement)
reduce_domain (ImageEllipse, CrossComplement, ImageEllipseReduced)
edges_sub_pix (ImageEllipseReduced, EdgesIncomplete, 'mderiche2', 0.5, 20, 40)
* Now the difficult case:
* First, make a fit to the individual arcs.
fit_ellipse_contour_xld (EdgesIncomplete, 'fitzgibbon', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
* Now we would have to determine which elliptic arcs should be merged.
* We assume that the customer is able to do this.
* If not, this could be done by clustering the elliptic arcs based on the centers
* and radii that result from the above fit.
* 
* Now we have to determine in which order the arcs should be merged.
* This can be done by sorting them according to their StartPhi.
Order := sort_index(StartPhi)
* Now construct a new contour from the coordinates of the segments to be merged:
RowsMerged := []
ColsMerged := []
for I := 0 to |Order| - 1 by 1
    select_obj (EdgesIncomplete, SelectedEdge, Order[I] + 1)
    get_contour_xld (SelectedEdge, Rows, Cols)
    if (PointOrder[Order[I]] == 'negative')
        Rows := inverse(Rows)
        Cols := inverse(Cols)
    endif
    RowsMerged := [RowsMerged,Rows]
    ColsMerged := [ColsMerged,Cols]
endfor
dev_set_color ('blue')
gen_contour_polygon_xld (Contour, RowsMerged, ColsMerged)
fit_ellipse_contour_xld (Contour, 'fitzgibbon', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
dev_set_color ('red')
gen_ellipse_contour_xld (ContEllipseIncomplete, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, 1.5)

clip_contours_xld 亚像素边缘分割案例

在这里插入图片描述

* 
* This example program shows how to use clip_contours_xld.
* 
* 
dev_close_window ()
read_image (Angio, 'angio-part')
get_image_size (Angio, Width, Height)
dev_open_window (0, 0, 3 * Width / 2, 3 * Height / 2, 'black', WindowID)
dev_set_part (0, 0, Height - 1, Width - 1)
* 
* Preparation: extract contours from an image.
* 检测线条
lines_gauss (Angio, Lines, 2.3, 0.0, 0.7, 'dark', 'true', 'parabolic', 'true')
dev_display (Angio)
dev_set_color ('yellow')
dev_display (Lines)
stop ()
* 
* Now reduce the image domain. The previously extracted contours
* are clipped accordingly (the original contours are displayed in gray).
* Note, that the  clipped contours end not at the pixel border,
* but at the last contour point that lies within the pixel.
Top := 200
Left := 100
Bottom := 300
Right := 200
gen_rectangle1 (Rectangle, Top, Left, Bottom, Right)
reduce_domain (Angio, Rectangle, AngioReduced)
* 亚像素边缘分割
clip_contours_xld (Lines, LinesClipped, Top, Left, Bottom, Right)
dev_clear_window ()
dev_display (AngioReduced)
dev_set_color ('dim gray')
dev_display (Lines)
dev_set_color ('yellow')
dev_display (LinesClipped)
stop ()
* 
dev_set_color ('white')
disp_arrow (WindowID, 198, 130, 153, 175, 1)
dev_open_window (25, 275, 300, 300, 'black', ZoomWindow)
dev_set_part (198, 126, 202, 130)
dev_display (AngioReduced)
dev_set_color ('dim gray')
dev_display (Lines)
dev_set_color ('yellow')
dev_display (LinesClipped)
stop ()
* 
dev_set_part (0, 0, Height - 1, Width - 1)
dev_close_window ()
dev_set_color ('black')
dev_set_line_width (2)
disp_arrow (WindowID, 198, 130, 153, 175, 1)

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/360241.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【总线接口】3.常见总线、接口GPIO、I2C、SPI、I2S、Modbus

初接触硬件,五花八门的总线、接口一定会让你有些疑惑,我尝试用一系列文章来解开你的疑惑。 系列文章 【总线接口】1.以Xilinx开发板为例,直观的认识硬件接口 【总线接口】2.学习硬件这些年接触过的硬件接口、总线 大汇总 【总线接口】3.常见…

单片机开发通用功能组件

mcu_reuse_development_module 单片机可复用、可通用开发组件,是以中间件思想开发的一套功能模块,将具有代表性或使用次数较多的功能和协议栈封装为独立的组件供开发者使用,开发者仅需通过组件提供的接口对接驱动层和应用层即可使用组件功能…

【PyTorch实战演练】Fast R-CNN中的RoI(Region of Interest)池化详解

文章目录 0. 前言1. ROI池化的提出背景2. RoI池化的结构与工作原理3. RoI池化的作用及意义4. RoI使用示例 0. 前言 按照国际惯例,首先声明:本文只是我自己学习的理解,虽然参考了他人的宝贵见解及成果,但是内容可能存在不准确的地方…

Kaggle竞赛系列_SpaceshipTitanic金牌方案分析_数据分析

文章目录 【文章系列】【前言】【比赛简介】【正文】(一)数据获取(二)数据分析1. 缺失值2. 重复值3. 属性类型分析4. 类别分析5. 分析目标数值占比 (三)属性分析1. 对年龄Age分析(1)…

Activiti工作流引擎

一、工作流介绍: 1.1 概念: 工作流(Workflow),就是通过计算机对业务流程自动化执行管理。它主要解决的是“使在多个参与者之间按照某种预定义的规则自动进行传递文档、信息或任务的过程,从而实现某个预期的业务目标,或…

【golang】22、functional options | 函数式编程、闭包

文章目录 一、配置 Option1.1 options1.2 funcitonal options 一、配置 Option 1.1 options https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html I’ve been trying on and off to find a nice way to deal with setting options in a…

Flink中StateBackend(工作状态)与Checkpoint(状态快照)的关系

State Backends 由 Flink 管理的 keyed state 是一种分片的键/值存储,每个 keyed state 的工作副本都保存在负责该键的 taskmanager 本地中。另外,Operator state 也保存在机器节点本地。Flink 定期获取所有状态的快照,并将这些快照复制到持…

Python面向对象编程:探索代码的结构之美

文章目录 一、引言二、为什么学习面向对象编程2.1 提高代码的可维护性:通过封装、继承和多态实现模块化设计2.2 提升代码的复用性:通过类和对象的创建实现代码的重用 三、类和对象的基本概念3.1 类和对象的定义和关系:类是对象的模板&#xf…

通过Nacos权重配置,实现微服务金丝雀发布效果(不停机部署)

在微服务项目迭代的过程中,不可避免需要上线;上线对应着部署,或者升级部署;部署对应着修改,修改则意味着风险。 传统的部署都需要先停止旧系统,然后部署新系统,之后需要对新系统进行全面的功能测试&#xf…

力扣hot100 n皇后 满注释版 通俗易懂

Problem: 51. N 皇后 文章目录 思路Code 思路 &#x1f468;‍&#x1f3eb; 参考地址 考虑每一行哪个位置放皇后判断是否合法递归下一行 Code class Solution {int n;char[][] board;List<List<String>> res new ArrayList<>();public List<List&l…

python_蓝桥杯刷题记录_笔记_入门2

前言 现在正式进入蓝桥杯的刷题啦&#xff0c;用python来做算法题&#xff0c;因为我之前其实都是用C来做题的&#xff0c;但是今年的话我打算换python来试试&#xff0c;很明显因为也才这学期接触python 加上之前C做题也比较菜&#xff0c;所以我打算用python重新来做题&#…

常用抓包软件集合(Fiddler、Charles)

1. Fiddler 介绍&#xff1a;Fiddler是一个免费的HTTP和HTTPS调试工具&#xff0c;支持Windows平台。它可以捕获HTTP和HTTPS流量&#xff0c;并提供了丰富的调试和分析功能。优点&#xff1a;易于安装、易于使用、支持多种扩展、可以提高开发效率。缺点&#xff1a;只支持Wind…

向上调整向下调整算法

目录 AdjustUp向上调整 AdjustDown向下调整 AdjustUp向上调整 前提是&#xff1a;插入数据之后&#xff0c;除去插入的数据其他的数据还是为堆 应用&#xff1a;插入数据。 先插入一个10到数组的尾上&#xff0c;再进行向上调整算法&#xff0c;直到满足堆。 性质&#xff1…

SD卡写保护无法格式化怎么办?

一般来说&#xff0c;写保护&#xff08;也称为只读&#xff09;是数据存储设备防止写入新数据或修改旧信息的能力。换句话说&#xff0c;您可以读取存储在磁盘上的信息&#xff0c;但是却不能删除、更改或复制它们&#xff0c;因为访问会被拒绝。那么SD卡有写保护怎么格式化呢…

Vue(十九):ElementUI 扩展实现树形结构表格组件的勾父选子、半勾选、过滤出半勾选节点功能

效果 原理分析 从后端获取数据后,判断当前节点是否勾选,从而判断是否勾选子节点勾选当前节点时,子节点均勾选全勾选与半勾选与不勾选的样式处理全勾选和全取消勾选的逻辑筛选出半勾选的节点定义变量 import {computed, nextTick, reactive, ref} from vue; import {tree} f…

解决打开页面显示源代码和乱码

用系统记事本打开 点击文件》另存为 选择编码&#xff1a;ANSI 保存》要替换它吗?》是 重新打开页面&#xff0c;显示正常&#xff0c;解决问题。

D2025——双通道音频功率放大电路,外接元件少, 通道分离性好,3V 的低压下可正常使用

D2025 为立体声音频功率放大集成电路&#xff0c;适用于各类袖珍或便携式立体声 收录机中作功率放放大器。 D2025 采用 DIP16 封装形式。 主要特点&#xff1a;  适用于立体声或 BTL 工作模式  外接元件少  通道分离性好  电源电压范围宽&#xff08;3V~12V…

Jenkins自动化打包

Jenkins自动化打包 下载安装 我们直接从官网https://www.jenkins.io/download/ 下载所需的Jenkins文件 如上图所示, 选择Windows版本,下面就是一路安装即可,需要注意的是,选择作为系统服务选项, 不要自己设置账号密码登录. Web配置 安装完根据提示在浏览器打开 http://lo…

01、全文检索 ------ 反向索引库 与 Lucene 的介绍

目录 全文检索 ------ 反向索引库 与 LuceneSQL模糊查询的问题反向索引库反向索引库的查询 Lucene&#xff08;全文检索技术&#xff09;Lucene能做什么Lucene存在的问题Solr 和 Elasticsearch 与 Lucene 的关系 全文检索 ------ 反向索引库 与 Lucene MySQL一些索引词汇解释 …

故障诊断 | 一文解决,BP神经网络的故障诊断(Matlab)

文章目录 效果一览文章概述专栏介绍模型描述源码设计参考资料效果一览 文章概述 故障诊断 | 一文解决,BP神经网络的故障诊断(Matlab) 专栏介绍 订阅【故障诊断】专栏,不定期更新机器学习和深度学习在故障诊断中的应用;订阅