halcon查找方形管材接头边缘
By
admin
at 2019-10-03 • 0人收藏 • 1898人看过
winform.button.oncommand = function(id,event){ if(i>5){ i=1 } var Image = HOperatorSetX.ReadImage("C:\Users\Public\Documents\MVTec\HALCON-13.0\examples\images\square_tube/square_tube_0"++i); //中值滤波器,消除噪声 var ImageMedian = HOperatorSetX.MedianImage( Image, 'circle', 2, 'mirrored' ); //对一副图像采取磁滞门限操作,低于Low的灰度值舍去 高于High 的灰度值保留,中间的看情况 var RegionHysteresis = HOperatorSetX.HysteresisThreshold( ImageMedian, 25, 25, 60 ); //闭运算(先膨胀—后腐蚀)去除毛刺 var RegionClosing = HOperatorSetX.ClosingCircle( RegionHysteresis, 8 ); //选区转换 convex:凸包性 var RegionTrans = HOperatorSetX.ShapeTrans( RegionClosing, 'convex' ); //膨胀 var RegionDilation = HOperatorSetX.DilationCircle( RegionTrans, 10 ); //腐蚀 var RegionErosion = HOperatorSetX.ErosionCircle( RegionTrans, 10 ); //求两个选区的不同区域 var RegionOfInterest = HOperatorSetX.Difference( RegionDilation, RegionErosion ); //设置操作区间(俗称截图) var ImageReduced = HOperatorSetX.ReduceDomain( ImageMedian, RegionOfInterest ); //亚像素边缘提取 var Edges = HOperatorSetX.EdgesSubPix( ImageReduced, 'canny', 1.5, 10, 35 ); //选择边缘(长度在50-9999的) var SelectedXLD = HOperatorSetX.SelectShapeXld( Edges, 'contlength', 'and', 50, 999999 ); //合并终点连接在一起的轮廓 var UnionContours = HOperatorSetX.UnionAdjacentContoursXld( SelectedXLD, 10, 1, 'attr_keep' ); //闭合轮廓 var ClosedContours = HOperatorSetX.CloseContoursXld( UnionContours ); HOperatorSetX.SetLineWidth( WindowHandle , 3 ); HOperatorSetX.SetDraw( WindowHandle , 'margin' ); HOperatorSetX.SetColor( WindowHandle , 'blue' ); HOperatorSetX.DispObj( Image , WindowHandle ); HOperatorSetX.DispObj( ClosedContours , WindowHandle ); i++; }
通过对具有一定形态学特征的he域进行缩小,提取出方管的轮廓,然后对边缘进行提取和统一。
登录后方可回帖