反向图像搜索

时间:2020-07-12 16:59:24

标签: c# image search

是否有任何方法可以反转图像搜索?而不是从左上角扫描到右下角,而是从左下角扫描到右上角?

这就是我扫描图像的方式

            for (int y = 0; y < matches.GetLength(0); y++)
            {
                for (int x = 0; x < matches.GetLength(1); x++)
                {
                    double matchScore = matches[y, x, 0];
                    if (matchScore > threshold)
                    {
                        Console.WriteLine("There is a Match");
                        Console.WriteLine($"Coords: {x},{y}");
                        return new Point(x, y);
                    }
                }
            }
            return new Point(-1, -1);

我只是扫描屏幕截图并使用emgu.cv找到匹配项

我可以从底部开始而不是从顶部开始反转扫描吗?

比方说,X100,Y100和X350,Y350有2场比赛

它应该从X350-> X100扫描,而不是X100-> X350,然后返回X350,Y350

1 个答案:

答案 0 :(得分:0)

您可以写:

for ( int y = matches.GetLength(0) - 1; y >= 0; y-- )
  for ( int x = matches.GetLength(1) - 1; x >= 0; x-- )
    if ( matches[y, x, 0] > threshold )
    {
      Console.WriteLine("There is a Match");
      Console.WriteLine($"Coords: {x},{y}");
      return new Point(x, y);
    }

由于您返回找到的第一个搜索元素,因此此循环和您可能找不到相同的结果,例如,如果您在顶部找到第一个元素,而在底部找到第一个元素,则返回顶部元素,而此元素返回底部元素...

选择循环方向取决于您要首先返回的内容,即从上至下或从下至上,以及从左至右或从右至左。