根据道路主线画边界线

        /// <summary>
        /// 通过中心线关键点获取左右辅助线关键点
        /// </summary>
        /// <param name="centerPoints">中心线关键点</param>
        /// <param name="leftWidth">道路左距离</param>
        /// <param name="rightWidth">道路右距离</param>
        /// <returns>左右辅助线的点集合</returns>
        private Tuple<Point[], Point[]> GetAuxiliaryLinePointsByCenterLinePoints(Collection<Point> centerPoints, double leftWidth, double rightWidth)
        {
            int pointCount = centerPoints.Count;
            Point[] leftPoints = new Point[pointCount],
                rightPoints = new Point[pointCount];

            for (int i = 1; i < pointCount; i++)
            {
                if (centerPoints[i].X.Equals(centerPoints[i - 1].X))
                {
                    if (centerPoints[i].Y > centerPoints[i - 1].Y)
                    {
                        leftPoints[i - 1] = new Point(centerPoints[i - 1].X - leftWidth, centerPoints[i - 1].Y);
                        leftPoints[i] = new Point(centerPoints[i].X - leftWidth, centerPoints[i].Y);
                        rightPoints[i - 1] = new Point(centerPoints[i - 1].X + rightWidth, centerPoints[i - 1].Y);
                        rightPoints[i] = new Point(centerPoints[i].X + rightWidth, centerPoints[i].Y);
                    }
                    else
                    {
                        leftPoints[i - 1] = new Point(centerPoints[i - 1].X + leftWidth, centerPoints[i - 1].Y);
                        leftPoints[i] = new Point(centerPoints[i].X + leftWidth, centerPoints[i].Y);
                        rightPoints[i - 1] = new Point(centerPoints[i - 1].X - rightWidth, centerPoints[i - 1].Y);
                        rightPoints[i] = new Point(centerPoints[i].X - rightWidth, centerPoints[i].Y);
                    }

                }
                else
                {
                    Point[] pointsleft1 =
                                GetPointsOfDistanceToPointOnTheLine(new Point[] { centerPoints[i - 1], centerPoints[i] },
                                    leftWidth, true);
                    Point[] pointsleft2 =
                       GetPointsOfDistanceToPointOnTheLine(new Point[] { centerPoints[i - 1], centerPoints[i] },
                           leftWidth, false);
                    Point[] pointsRight1 =
                        GetPointsOfDistanceToPointOnTheLine(new Point[] { centerPoints[i - 1], centerPoints[i] },
                            rightWidth, true);
                    Point[] pointsRight2 =
                      GetPointsOfDistanceToPointOnTheLine(new Point[] { centerPoints[i - 1], centerPoints[i] },
                          rightWidth, false);
                    if (centerPoints[i].Y > centerPoints[i - 1].Y)
                    {
                        leftPoints[i - 1] = pointsleft1[0];
                        leftPoints[i] = pointsleft2[0];
                        rightPoints[i - 1] = pointsRight1[1];
                        rightPoints[i] = pointsRight2[1];
                    }
                    else
                    {
                        leftPoints[i - 1] = pointsleft1[1];
                        leftPoints[i] = pointsleft2[1];
                        rightPoints[i - 1] = pointsRight1[0];
                        rightPoints[i] = pointsRight2[0];
                    }
                }
                if (i != 1)
                {
                    Point tempLeftPoint, tempRightPoint;
                    tempLeftPoint = leftPoints[i - 1];
                    tempRightPoint = rightPoints[i - 1];

                    Point[] leftOutsideRoadPoints = new Point[4];
                    leftOutsideRoadPoints[0] = leftPoints[i - 2];
                    leftOutsideRoadPoints[1] = leftPoints[i - 1];
                    leftOutsideRoadPoints[2] = tempLeftPoint;
                    leftOutsideRoadPoints[3] = leftPoints[i];
                    Point leftIntersectiony = GetIntersectionyOfTwoLines(leftOutsideRoadPoints);
                    leftPoints[i - 1] = leftIntersectiony;

                    Point[] rightOutsideRoadPoints = new Point[4];
                    rightOutsideRoadPoints[0] = rightPoints[i - 2];
                    rightOutsideRoadPoints[1] = rightPoints[i - 1];
                    rightOutsideRoadPoints[2] = tempRightPoint;
                    rightOutsideRoadPoints[3] = rightPoints[i];
                    Point rightIntersectiony = GetIntersectionyOfTwoLines(rightOutsideRoadPoints);
                    rightPoints[i - 1] = rightIntersectiony;
                }
            }
            return new Tuple<Point[], Point[]>(leftPoints, rightPoints);
        }

        /// <summary>
        /// 求到直线固定点、固定距离的点坐标
        /// </summary>
        /// <param name="linePoint">确定一条直线的两个点</param>
        /// <param name="distance">到直线的距离</param>
        /// <param name="relativeFristPoint">所求点是对应直线两点的哪一个:true-对应linePoint[0]点;false-对应linePoint[1]点</param>
        /// <returns>到直线上特定点固定距离的两个点数组</returns>
        private Point[] GetPointsOfDistanceToPointOnTheLine(Point[] linePoint, double distance, bool relativeFristPoint = true)
        {
            Point[] points = new Point[2];

            Point relativePoint = relativeFristPoint ? linePoint[0] : linePoint[1];

            if (linePoint.Length != 2)
                throw new AggregateException("参数个数不正确");

            if (linePoint[0].Equals(linePoint[1]) && Math.Abs(distance) < 0.1)
                throw new ArgumentException("参数不正确");

            if (linePoint[0].X.Equals(linePoint[1].X))   //垂直直线
            {
                points[0] = new Point(relativePoint.X - distance, relativePoint.Y);
                points[1] = new Point(relativePoint.X + distance, relativePoint.Y);
            }
            else if (linePoint[0].Y.Equals(linePoint[1].Y))   //水平直线
            {
                points[0] = new Point(relativePoint.X, relativePoint.Y + distance);
                points[1] = new Point(relativePoint.X, relativePoint.Y - distance);
            }
            else
            {
                double differenceY = linePoint[1].Y - linePoint[0].Y;
                double differenceX = linePoint[1].X - linePoint[0].X;

                double centerValue = Math.Sqrt(Math.Pow(distance, 2) - (1 + Math.Pow(differenceY / differenceX, 2)));

                double getX1 = relativePoint.X + centerValue;
                double getY1 = differenceX * (relativePoint.X - getX1) / differenceY + relativePoint.Y;
                points[1] = new Point(getX1, getY1);

                double getX2 = relativePoint.X - centerValue;
                double getY2 = differenceX * (relativePoint.X - getX2) / differenceY + relativePoint.Y;
                points[0] = new Point(getX2, getY2);
            }

            return points;
        }

        /// <summary>
        /// 求两条线的交点
        /// </summary>
        /// <param name="point">前两个点与后两个点分别确定两条直线</param>
        /// <returns>两直线焦点</returns>
        private Point GetIntersectionyOfTwoLines(Point[] point)
        {
            Point intersectiony = new Point();

            if (point.Length != 4)
                throw new AggregateException("参数个数不正确");

            if (point[0].Equals(point[1]) && point[2].Equals(point[4]))
                throw new ArgumentException("参数相同");

            bool line1IsVertical, line2IsVertical;
            line1IsVertical = point[1].X.Equals(point[0].X);
            line2IsVertical = point[3].X.Equals(point[2].X);

            if (line1IsVertical || line2IsVertical)  //两条直线存在垂直的情况
            {
                if (line1IsVertical && line2IsVertical)
                {
                    throw new ArgumentException("两直线平行,无交点");
                }
                else
                {
                    if (line1IsVertical)
                    {
                        intersectiony.X = point[0].X;

                        double differenceX = point[3].X - point[2].X;
                        double differenceY = point[3].Y - point[2].Y;

                        intersectiony.Y = differenceY * (intersectiony.X - point[2].X) / differenceX + point[2].Y;
                    }
                    else
                    {
                        intersectiony.X = point[2].X;

                        double differenceX = point[1].X - point[0].X;
                        double differenceY = point[1].Y - point[0].Y;

                        intersectiony.Y = differenceY * (intersectiony.X - point[0].X) / differenceX + point[0].Y;
                    }
                }
            }
            else
            {
                double differenceX1 = point[1].X - point[0].X;
                double differenceX2 = point[3].X - point[2].X;
                double differenceY1 = point[1].Y - point[0].Y;
                double differenceY2 = point[3].Y - point[2].Y;

                if ((differenceY1 * differenceX2).Equals(differenceY2 * differenceX1))
                {
                    throw new ArgumentException("两直线平行,无交点");
                }
                else
                {
                    intersectiony.X = (point[0].Y - point[2].Y + differenceY2 * point[2].X / differenceX2 - differenceY1 * point[0].X / differenceX1) /
                                      (differenceY2 / differenceX2 - differenceY1 / differenceX1);
                    intersectiony.Y = differenceY1 * (intersectiony.X - point[0].X) / differenceX1 + point[0].Y;
                }
            }

            return intersectiony;
        }
时间: 2024-12-11 07:47:12

根据道路主线画边界线的相关文章

深度学习大规模道路网络自动提取

好久没有更新了,近期做了一个工作,就是用深度学习方法来自动提取高分辨率遥感影像上的道路网络,16年的时候都是用的什么SVM,什么增强线性指数等 手工设计的线性目标增强特征,然后去提取道路,那些个东西说白了,没啥用,在一个小区域可能做的有那么点效果,但是换一个场景,立马就没了,没有任何普适性 可言,之前用深度学习方法做过高分辨率影像变化监测工作,这一次,我重新把网络进行了设计,用于提取道路网络,最终生成道路中心,并进行大规模场景实验,结果 还是非常不错的,个人觉得在一定程度上可以减少人工提取道路网

C++并发多线程(一)

并发:两个或者更多的任务同时发生,一个程序同时执行多个独立的任务. 以往计算机 单核CPU 某一个时刻只能执行一个任务 由操作系统调度 每秒钟进行多次所谓的任务切换并发的假象(不是真正的并发),这种切换(上下文切换)时要有时间开销的. 线程 每个进程(执行起来的可执行程序),都有一个主线程 这个主线程是唯一的 也就是一个进程中只能有一个主线程.当你执行要给刻执行程序 ,产生了一个进程后 这个主线程就随着这个进程默默启动起来了ctrl+f5运行这个程序的时候,实际上是进程的主线程来执行 这个mai

画出决策边界线--plot_2d_separator.py源代码【来自python机器学习基础教程】

1 import numpy as np 2 import matplotlib.pyplot as plt 3 from .plot_helpers import cm2, cm3, discrete_scatter 4 5 def _call_classifier_chunked(classifier_pred_or_decide, X): 6 # The chunk_size is used to chunk the large arrays to work with x86 7 # me

SpringMVC深度探险(三) —— DispatcherServlet与初始化主线

本文是专栏文章(SpringMVC深度探险)系列的文章之一,博客地址为:http://downpour.iteye.com/blog/1341459. 在上一篇文章中,我们给出了构成SpringMVC应用程序的三要素以及三要素的设计过程.让我们来归纳一下整个设计过程中的一些要点: SpringMVC将Http处理流程抽象为一个又一个处理单元 SpringMVC定义了一系列组件(接口)与所有的处理单元对应起来 SpringMVC由DispatcherServlet贯穿始终,并将所有的组件串联起来

一种简单的道路模型

读过很多道路追踪的论文,经常都需要道路模型的建模.我不知道是不是因为自己太笨还是怎样,好多人建的模型我实在无法理解他的用意何在,而且我真的深刻怀疑他们那些模型的参数是不是真的可以求出来.就比如这篇文章"lane detection and tracking using a new lane model and distance transform",我实在无法理解他的建模,还有他的建模参数到底如何求解: 我无法理解他为什么要设置那个角度,我也不知道那个顶点的位置如何获取,如果有大神知道

iOS 百度地图 轨迹记录 道路贴合

最近在做一个小的demo,试一下轨迹记录. 记录轨迹需要不停的获取位置记录到数据库. 在画折现的时候会在道路拐角处直接连线,不会与道路贴合,在这说一下我的解决方案. 我调用了百度地图的路径规划api.这样就能实现路径贴合功能了. 在此附上dome:点击打开链接 强调:这个dome是真机上运行,在模拟器上会报错.下载的时候注意一下. 由于各种原因图片是用手机拍的. 上张图看看: 核心代码: 调用驾车线路规划,规划出从这点到那点的线路然后画出路线,生成的线路在下面函数中获得. - (void)onG

Android OpenGL ES 画球体

最近因为兴趣所向,开始学习OpenGL绘图.本文以"画球体"为点,小结一下最近所学. > 初识OpenGL ES 接触OpenGL是从Android开始的.众所周知,Android View 是线程不安全的,于是只允许在主线程中对View进行操作.然而假如我们需要实现复杂的界面,特别是开发游戏,在主线程中画大量图像,会耗费比较长的时间,使得主线程没能及时响应用户输入,甚至出现ANR.于是Android提供了一个 SurfaceView类,通过双缓冲机制(两块画布?三块画布?),允

Qt自己定义事件实现及子线程向主线程传送事件消息

近期在又一次学习Qt的时候,由于要涉及到子线程与主线程传递消息,所以便琢磨了一下.顺便把有用的记录下来,方便自己以后查询及各位同仁的參考! 特此声明,本篇博文主要讲述有用的,也就是直接说明怎么实现,就不打算陈述一大堆理论啦,只是,还是建议大家去查查对应的理论比較好.这样能对Qt的消息传送机制的理解更加深入. 依据网上大多数人的资料,要实现自己定义消息,须要从QEvent 派生一个自己定义的事件:事实上也能够不须要,仅仅要使用QEvent::Type自己定义一个事件即可了. 在这里,本人把两种实现

BZOJ 2500 幸福的道路

题面: 2500: 幸福的道路 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 366  Solved: 144[Submit][Status][Discuss] Description 小T与小L终于决定走在一起,他们不想浪费在一起的每一分每一秒,所以他们决定每天早上一同晨练来享受在一起的时光. 他们画出了晨练路线的草图,眼尖的小T发现可以用树来描绘这个草图. 他们不愿枯燥的每天从同一个地方开始他们的锻炼,所以他们准备给起点标号后顺序地从每个起点