首页 > 编程语言 >点集从上到下,从左到右进行Z字型排序(C++与python实现,自写)

点集从上到下,从左到右进行Z字型排序(C++与python实现,自写)

时间:2023-03-17 10:58:19浏览次数:34  
标签:OutPoints vector 自写 _. python iter PNews Points C++

C++实现:

void PointDisgus(vector<Point>& Points) {
    Point t;
    int n = Points.size();
    int i, j;
    vector<Point> OutPoints;
    vector<Point> Points_ = Points;
    std::sort(Points_.begin(), Points_.end(), compareValue_y);
    for (vector<Point>::iterator iter = Points_.begin(); iter != Points_.end(); iter++)
    {
        vector<Point> PNews;
        int index = iter - Points_.begin();
        Point P = *iter;
        for (int i = index; i < n; i++)
        {
            if (abs(P.y - Points_[i].y) < 12)    // 两个点在图中并不一定水平,设置一定偏差
            {
                PNews.push_back(Points_[i]);
                iter++;
            }
        }
        std::sort(PNews.begin(), PNews.end(), compareValue_x);
        for (auto pp : PNews) {
            OutPoints.push_back(pp);
        }
        iter = iter - 1;
        PNews.clear();
    }
    Points = OutPoints;
}

python实现:

def PointDisgus(Points):
    n = len(Points)
    Points_ = Points
    Points_.sort(key=lambda elem: elem[1])
    OutPoints = []
    a = 0
    for i, P in enumerate(Points_):
        PNews = []
        if i < a:
            continue
        for j in range(i, n):
            if abs(P[1] - Points_[j][1]) < 30:  # 设置y方向上的偏差
                PNews.append(Points_[j])
                a += 1
        PNews.sort(key=lambda elem: elem[0])
        for pp in PNews:
            OutPoints.append(pp)
        PNews.clear()
    return OutPoints

 

标签:OutPoints,vector,自写,_.,python,iter,PNews,Points,C++
From: https://www.cnblogs.com/cn-gzb/p/17225788.html

相关文章

  • Python pyyaml报错:TypeError load() missing 1 required positional argument ‘Loade
    直接开门见山,一个小报错。报错:ERROR-load()missing1requiredpositionalargument:'Loader'报错行:config=yaml.load(f)报错原因:......
  • C++11lambda表达式精讲
    lambda表达式的概念和基本用法lambda表达式定义了一个匿名函数,并且可以捕获一定范围内的变量。lambda表达式的语法形式可简单归纳如下:[capture](params)opt->......
  • 黑马阶段三 C++篇 02day
    2day1.引用是什么:给变量空间取别名intmain(){inta=0;int&b=a;b=100;cout<<a<<endl;return0;}2.引用的注意使用引用类型可以像指针那样访问只......
  • 接口自动化---数据库断言封装python
    接口自动化---数据库断言封装python前言:在接口测试响应验证中,通常可以通过接口响应值来验证,还可以通过查询数据库信息辅助来验证。接口测试数据清理1、通过Delete接口删......
  • 68.C++中的const
      编写程序过程中,我们有时不希望改变某个变量的值。此时就可以使用关键字const对变量的类型加以限定。初始化和const  因为const对象一旦创建后其值就不能再改变,所......
  • 人工智能python3+tensorflow人脸识别_使用 face-api.js 在你的浏览器中做人脸识别(基于
    我很兴奋地告诉你,终于可以在浏览器中运行人脸识别了!这篇文章我将介绍face-api.js,这个类库构建于tensorflow.js之上。它实现了多个CNNs(卷积神经网络)以解决人脸检测、......
  • 【Python】使用 multiprocessing.dummy 执行多线程任务
    1.#-*-coding:utf-8-*-2.#frommultiprocessingimportPool多进程3.frommultiprocessing.dummyimportPoolasThreadPool#多线程4.importtime5.im......
  • Python脚本运行出现语法错误:IndentationError:unexpected indent
    【问题】 一个python脚本,本来都运行好好的,然后写了几行代码,而且也都确保每行都对齐了,但是运行的时候,却出现语法错误: IndentationError: unexpectedindent【解决过程......
  • Python代码块批量添加Tab缩进
    选择一个合适的编辑器,比如notepad++、VS、eclipse、sublimetext等,选中要集体缩进的代码块,按Tab:集体缩进(向右)按Shift+Tab:集体回缩(向左)在Notepad++等编辑器中也有将Tab......
  • Python编程规范
    Python编码规范(Google)引自菜鸟:https://www.runoob.com/w3cnote/google-python-styleguide.html分类编程技术Python风格规范(Google)本项目并非Google官方项目,......