fit_line_contour_xld的bug

fit_line_contour_xld (BottomEdgeContours, 'huber', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist) 
存在bug,结果RowBegin, ColBegin, RowEnd, ColEnd两点重合,这个时候需要Nr, Nc, Dist计算直线。

fit_line_contour_xld approximates the XLD contours Contours by line segments. It does not perform a segmentation of the input contours. Thus, one has to make sure that each contour corresponds to one and only one line segment. The operator returns for each contour the start point (RowBegin, ColBegin), the end point (RowEnd, ColEnd), and the regression line to the contour given by the normal vector (Nr, Nc) of the line and its distance Dist from the origin, i.e., the line equation is given by

 

就只能用 R*Nr+C*Nc-Dist=0的关系来求直线

            int MeasureDotNum = 20;
            int DeltaMeasureDistance;
            DeltaMeasureDistance = Convert.ToInt32(BoardLength / (MeasureDotNum + 1));
 
            int[] MeasureDotColAry = new int[MeasureDotNum];
            for (int i = 1; i <= MeasureDotNum; i++)
            {
                MeasureDotColAry[i - 1] = tempCol1.I + DeltaMeasureDistance * i;
            }
 
            HTuple tempRowAry = new HTuple();
            HTuple tempColumnAry = new HTuple();
 
            HTuple MeasureHandle, tempRowEdge, tempColEdge, tempAmplitede, tempDistance;
 
for (int i = 0; i <= MeasureDotNum - 1; i++)
            {
                HOperatorSet.GenMeasureRectangle2(tempRow2, MeasureDotColAry[i], 1.5707963, 300, 20, tempImageWidth, tempImageHeight, "nearest_neighbor", out MeasureHandle);
                HOperatorSet.MeasurePos(tempImage, MeasureHandle, 1.2, 10, "positive", "first", out  tempRowEdge, out  tempColEdge, out  tempAmplitede, out tempDistance);
                HOperatorSet.CloseMeasure(MeasureHandle);
 
                HOperatorSet.TupleConcat(tempRowAry, tempRowEdge, out tempRowAry);
                HOperatorSet.TupleConcat(tempColumnAry, tempColEdge, out tempColumnAry);
            }
 
            int tempDotNum=tempRowAry.Length;
            if (tempDotNum < 2)
            {
                return false;
            }
 
            HObject tempPolygonRegion = null;
            HOperatorSet.GenRegionPolygon(out tempPolygonRegion, tempRowAry, tempColumnAry);
 
            HObject tempContourXld = null;
            HOperatorSet.GenContourRegionXld(tempPolygonRegion, out tempContourXld, "center");
 
            HTuple tempRowBegin, tempColumnBegin, tempRowEnd, tempColumnEnd,tempNr,tempNc,tempDist;
            HOperatorSet.FitLineContourXld(tempContourXld, "huber", -1, 0, 5, 2, out tempRowBegin, out tempColumnBegin, out tempRowEnd, out tempColumnEnd, out tempNr, out tempNc, out tempDist);
 
            tempPolygonRegion.Dispose();
            tempContourXld.Dispose();
 
            if (tempNr.Length<1)
            {
                return false;
            }
            double tempA,tempBx;
            tempBx = -tempNc.D / tempNr.D;
            tempA = tempDist.D / tempNr.D;
 /// 对一组点通过最小二乘法进行线性回归  y=A+x*Bx
posted @   QuincyYi  阅读(1246)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示