1. ramer-douglas-peucker
ramer-douglas-peucker,又称拉默-道格拉斯-普克算法
道格拉斯算法是一种直线简化算法,可以在保持曲线形状的同时减少曲线中的点数。
它的工作原理是递归地将曲线划分为更小的线段,并用一条线近似每个线段。然后,该算法检查原始曲线和近似直线之间的距离。
如果距离大于指定的公差,则算法会细分线段并重复该过程。如果距离小于公差,则算法会删除中间点,然后移动到下一个线段。
关于道格拉斯算法的具体实现过程,不在此赘述。来一版可以直接使用的c++代码,里面使用了递归。
// define a function to calculate the distance between two pointsfloat distance(cv::point2f p1, cv::point2f p2) { return std::sqrt(std::pow(p2.x - p1.x, 2) + std::pow(p2.y - p1.y, 2));}// define a function to find the point with the maximum distance from a line segmentcv::point2f find_furthest_point(std::vector points, cv::point2f p1, cv::point2f p2) { float max_distance = 0; cv::point2f furthest_point; for (auto point : points) { float current_distance = std::fabs((point.y - p1.y) * (p2.x - p1.x) - (point.x - p1.x) * (p2.y - p1.y)) / distance(p1, p2); if (current_distance > max_distance) { max_distance = current_distance; furthest_point = point; } } return furthest_point;}// define the douglas-peucker algorithm functionvoid douglas_peucker(std::vector points, float epsilon, std::vector& simplified_points) { // find the point with the maximum distance from the line segment float max_distance = 0; int furthest_index; cv::point2f p1 = points[0]; cv::point2f p2 = points.back(); for (int i = 1; i max_distance) { max_distance = current_distance; furthest_index = i; } } // if the maximum distance is greater than epsilon, recursively simplify the two sub-lines if (max_distance > epsilon) { std::vector left_points(points.begin(), points.begin() + furthest_index + 1); std::vector right_points(points.begin() + furthest_index, points.end()); std::vector left_simplified_points; std::vector right_simplified_points; douglas_peucker(left_points, epsilon, left_simplified_points); // recursively simplify the right sub-line douglas_peucker(right_points, epsilon, right_simplified_points); // combine the simplified sub-lines simplified_points.insert(simplified_points.end(), left_simplified_points.begin(), left_simplified_points.end()); simplified_points.insert(simplified_points.end(), right_simplified_points.begin() + 1, right_simplified_points.end()); } // if the maximum distance is less than or equal to epsilon, add the endpoints to the simplified points else { simplified_points.push_back(points.front()); simplified_points.push_back(points.back()); }}2. 道格拉斯算法的特点
道格拉斯算法,存在它的优势与劣势
优势:
该算法的实现和理解相对简单。
它可以用于简化任何类型的曲线,而不仅仅是直线或多段线。
通过调整公差参数,可以使用它来保留曲线的重要特征,例如拐角或拐点。
缺点:
对于大型数据集或复杂曲线,该算法耗时久。
所得到的简化曲线可能在视觉上不令人满意或不平滑,尤其是在公差参数设置过高的情况下。
该算法不适用于具有不同密度或曲率的曲线,因为它假设点的均匀分布。
因此在实际使用中,针对实际出现的问题,我们需要对该算法进行对应的优化。我在工程中已经出现了不平滑的问题,关于优化以后再说。
华为放弃收购3Leaf,致美国政府公开信全文
专业的的霍特币和仿霍特币矿机系统开发公司
黑莓将收购AI网络安全公司Cylance
解读新任鸿海董事候选名单的玄机
一文看懂数字对讲机通讯模块的串口通讯协议
自动驾驶特征点处理算法
特信无人机反制设备的简单介绍
STM32之RS485通讯方式实现
麒麟990 5G芯片究竟有多强
5G时代下的神器:高速光缆连接器组件
我国明确TD-LTE频率规划 频谱是TD-SCDMA数倍
揭秘新式平面光源 效率可超越OLED
三大运营商公布运营数据,上半年通信市场格局出现新变化
从“人机角力”到“人机融合”,流水线的百年进化史
NB-IoT将引爆智能可穿戴市场
珠海晨新科技有限公司荣获“珠海市科技创新先进单位”称号
土壤检测仪器管用吗
WT0023液晶段码显示驱动芯片概述及功能特点
自动驾驶系统作出正确的决策,要完成哪些计算机视觉任务?
小米澎湃s1定位中高端,会出现在小米6上吗?