【问题标题】:Sort points not correct排序点不正确
【发布时间】:2018-08-21 09:54:18
【问题描述】:

我想用 C# 对输出点进行排序 这是我的视觉输出

我的控制台输出是:

  • 388, 380
  • 388, 380
  • 220, 379
  • 388, 380
  • 220, 379
  • 53, 379
  • 388, 380
  • 220, 379
  • 53, 379
  • 53, 211
  • 388, 380
  • 220, 379
  • 53, 379
  • 53, 211
  • 391, 206
  • 388, 380
  • 220, 379
  • 53, 379
  • 53, 211
  • 220, 211
  • 391, 206
  • 388, 380
  • 220, 379
  • 53, 379
  • 53, 211
  • 220, 211
  • 391, 206
  • 220, 43
  • 388, 380
  • 220, 379
  • 53, 379
  • 53, 211
  • 220, 211
  • 391, 206
  • 220, 43
  • 52, 43
  • 388, 380
  • 220, 379
  • 53, 379
  • 53, 211
  • 220, 211
  • 391, 206
  • 220, 43
  • 52, 43
  • 389, 42

这是我的代码:

PosList.Add(cog);
PosList = PosList.OrderByDescending(p=>p.Y).ToList();

我无法对我的积分进行排序,请你帮我创建一个排序...

【问题讨论】:

  • 那么代码不足以理解您的问题。什么是齿轮?如何定义?请阅读如何发布minimal reproducible example
  • 代码太短,但应该生成一个按 Y 排序的列表。还要清楚地说明预期和实​​际结果。
  • @Steve cog 是 c# 中轮廓的输出点
  • @MazyarYousefiNia 您可能会发现阅读minimal reproducible example 很有价值。基本上,您应该做的是创建一个代码示例(包括填充List),我们可以将其复制并粘贴到控制台应用程序中并运行。 请务必指定您尝试生成的显式输出。
  • 您不仅应该与Y进行比较,还应与X进行比较。结果颜色:i.stack.imgur.com/h1OWY.png

标签: c# .net sorting opencv opencvsharp


【解决方案1】:

尝试以下:

            List<Point> points = new List<Point>() {
                new Point(388, 380),
                new Point(388, 380),
                new Point(220, 379),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(53, 211),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(53, 211),
                new Point(391, 206),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(53, 211),
                new Point(220, 211),
                new Point(391, 206),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(53, 211),
                new Point(220, 211),
                new Point(391, 206),
                new Point(220, 43),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(53, 211),
                new Point(220, 211),
                new Point(391, 206),
                new Point(220, 43),
                new Point(52, 43),
                new Point(388, 380),
                new Point(220, 379),
                new Point(53, 379),
                new Point(53, 211),
                new Point(220, 211),
                new Point(391, 206),
                new Point(220, 43),
                new Point(52, 43),
                new Point(389, 42)
            };


            List<List<Point>> sorted = points.OrderBy(x => x.Y).ThenBy(x => x.X).GroupBy(x => x.Y).Select(x => x.ToList()).ToList();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 2017-10-11
    相关资源
    最近更新 更多