我正在使用Opencv“ findChessboardCorners”功能查找棋盘的角,但是从“ findChessboardCorners”功能返回的值却是错误的。
以下是我的代码:
int main(int argc, char* argv[])
{
vector<vector<Point2f>> imagePoints;
Mat view;
bool found;
vector<Point2f> pointBuf;
Size boardSize; // The size of the board -> Number of items by width and height
boardSize.width = 75;
boardSize.height = 49;
view = cv::imread("FraunhoferChessBoard.jpeg");
namedWindow("Original Image", WINDOW_NORMAL);// Create a window for display.
imshow("Original Image", view);
found = findChessboardCorners(view, boardSize, pointBuf,
CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE);
if (found)
{
cout << "Corners of chess board detected";
}
else
{
cout << "Corners of chess board not detected";
}
waitKey(0);
return 0;
}
我希望从“ findChessboardCorners”函数返回的值是true,而我却是false。
请向我解释我在哪里犯了错误?
答案 0 :(得分:1)
该函数未在图像中找到图案,这就是为什么它返回false的原因。也许完全相同的代码可以处理不同的图像。
我无法直接回答为什么此功能无法在图像中找到图案,但是我建议使用其他方法以减少对噪点的敏感度,以便算法可以正确检测到您的角落:
-使用findChessboardCornersSB
代替findChessboardCorners
。根据文档,它对噪声更强健,并且对于像您这样的大图像更有效。那可能就是您要寻找的。我尝试过,并使用python与您发布的图像一起正常工作。请参阅下面的结果。
-如文档findChessboardCornersSB
所示更改图案形状。
-在图案中使用越来越少的正方形。有这么多正方形是无济于事的。
下一步,您将需要使用非对称模式。如果左上角的正方形是白色,则右下角必须是黑色。
如果方形图案还有其他问题,您也可以使用转角更改方法并切换到圆形图案。所有功能都在opencv中可用。就我而言,它效果更好。参见findCirclesGrid
。如果使用此方法,则可以运行“ BlobDetector”来检查如何检测每个圆并配置一些参数以提高精度。
希望这会有所帮助!
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('img.jpg')
img_small = cv2.resize(img, (img.shape[1], img.shape[0]))
found, corners = cv2.findChessboardCornersSB(img_small, (75, 49), flags=0)
plt.imshow(cv2.cvtColor(img_small, cv2.COLOR_BGR2RGB), cmap='gray')
plt.scatter(corners[:, 0, 0], corners[:, 0, 1])
plt.show()