如何对找到的棋盘边角进行排序? [英] How to sort found chessboard corners?

查看:148
本文介绍了如何对找到的棋盘边角进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对从棋盘上找到的边角进行排序有疑问. 我正在使用OpenCVSharp在C#中编写程序.

I have a question about sorting found corners from chessboard. I'm doing my program in C# using OpenCVSharp.

我需要对找到的角点进行排序,这些角点是由X和Y描述的. 这是我的代码的一部分:

I need to sort found corners which are points described by X and Y. This is the part of my code:

...
CvPoint2D32f[] corners;
bool found = Cv.FindChessboardCorners(gray, board_sz, out corners, out corner_count,
    ChessboardFlag.NormalizeImage | ChessboardFlag.FilterQuads);
Cv.FindCornerSubPix(gray, corners, corner_count, new CvSize(11,11), new CvSize(-1,-1),
    Cv.TermCriteria(CriteriaType.Epsilon | CriteriaType.Iteration, 30, 0.1));

Cv.DrawChessboardCorners(img1, board_sz, corners, found);
...

之后,我将在ImageBox中显示找到的角点

After that I'm displaying found corners in ImageBox:

看到良好的订单

这是我经常需要的转角顺序,但是当我稍微旋转棋盘时-发现转角的变化如下:

and this is the order of corners what I need always, but when I rotate the chessboard a bit - found corners changes like this:

看到不良订单

我总是需要这些点的顺序相同(如图1所示),所以我决定使用:

I need always the same (like in picture 1) order of these points so I decided to use:

var ordered = corners.OrderBy(p => p.Y).ThenBy(p => p.X);
corners = ordered.ToArray();

但是它不能像我想要的那样工作:

but it doesn't work like I want:

所有图片中看到不良结果1 /a>

see bad result 1 in all pictures

所有图片中看到不良结果2 /a>

see bad result 2 in all pictures

主要要点是,我的棋盘不会旋转太多,只是稍微旋转一下即可. 第二点是,必须从板左上方的第一个白色正方形开始对角进行排序. 我知道,基点(0,0)在图像的左上角,Y的正值在图像底部的方向上增加,而X的正值在图像右侧的方向上增加图片.

The main point is that my chessboard won't be rotated too much, just for a little angle. The second point is that the corners must be ordered from the first white square on the top left side of the board. I know, that the base point (0,0) is on the left top corner of the image and the positive values of Y are increasing in the direction to the bottom of image and positive values of X are increasing in direction to the right side of image.

我正在研究程序以获取此顺序(这些方式在图片编辑器中进行了编辑):

I'm working on the program to obtain this ordering (these pistures are edited in picture editor):

请参见所有图片中的示例1

请参见所有图片中的示例2

感谢您的帮助.

推荐答案

请在下面找到一些示例,以了解OpenCV的findChessboardCorners如何返回角点列表以及drawChessboardCorners如何显示角.

Please find below some examples for how OpenCV's findChessboardCorners might return the corner point list and how drawChessboardCorners might display the corners.

为清楚起见,将订阅四边形的索引顺序添加为0、1、2、3.

For more clarity the order of indices of the subscribing quadrilateral is added as 0,1,2,3.

基本上,结果有4种可能的旋转,导致初始红色标记为:

Basically there are 4 possible rotations of the result leading to the initial red marker being either:

  • topLeft
  • topRight
  • bottomLeft
  • bottomRight

因此,当您要求助时,可以考虑这些知识并相应地更改索引的顺序.好消息是,使用这种方法,您不必查看所有x,y值.比较列表中的第一个和最后一个值就足够了,以找出旋转角度.

So when you'd like to resort you can take this knowledge into account and change the order of indices accordingly. The good news is that with this approach you don't have to look at all the x,y values. It's sufficient to compare the first and last value in the list to find out what the rotation is.

为简化排序,您可能希望将列表重塑"为一个数组,该数组适合您在第一位置为findChessBoardCorners提供的象棋图案. 9x9.在python numpy中,有一个我不知道如何在C#中完成的功能.

To simplify the sorting you might want to "reshape" the list to an array that fits the chesspattern that you supplied to findChessBoardCorners in the fist place e.g. 9x9. In Python numpy there is a function for that i don't know how this would be done in C#.

这篇关于如何对找到的棋盘边角进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆