findChessboardCorners 无法找到超过 3x3 的棋盘

findChessboardCorners is unable to find chessboard beyond 3x3

我正在尝试使用棋盘法在 python 中校准相机。
这是我使用的代码:

import numpy as np
import cv2
import glob

x = 3
y = 3
# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((y*x,3), np.float32)
objp[:,:2] = np.mgrid[0:x,0:y].T.reshape(-1,2)

# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.

images = glob.glob('*.jpg')

for fname in images:
    img = cv2.imread(fname)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    # Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray, (x,y),None)

    # If found, add object points, image points (after refining them)
    if ret == True:
        objpoints.append(objp)

        corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
        imgpoints.append(corners2)

        # Draw and display the corners
        img = cv2.drawChessboardCorners(img, (x,y), corners2,ret)
        cv2.imshow('img', img)
        cv2.waitKey(500)

cv2.destroyAllWindows()

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
img = cv2.imread('pic0.jpg')
h,  w = img.shape[:2]
newcameramtx, roi=cv2.getOptimalNewCameraMatrix(mtx,dist,(w,h),1,(w,h))
# undistort
mapx,mapy = cv2.initUndistortRectifyMap(mtx,dist,None,newcameramtx,(w,h),5)
dst = cv2.remap(img,mapx,mapy,cv2.INTER_LINEAR)

# crop the image
x,y,w,h = roi
dst = dst[y:y+h, x:x+w]
cv2.imwrite('calibresult.png',dst)

x 和 y 用于图案的大小。
这是我正在处理的图像。

findChessboardCorners 方法似乎无法找到超过 3x3 大小的棋盘图案。我已经尝试将图像二值化并增加对比度,但我无法检索到更大的图案。
是我处理的图像太差还是我做错了什么?

正如 Nullman 所说,您将棋盘内角的大小定义为 3x3。在您提供的示例图片中,内角尺寸为 14x6。因此,代码将是:

ret, corners = cv2.findChessboardCorners(gray, (14,6),None)

中的(x,y)

cv2.findChessboardCorners(gray, (x,y),None)

是你的板的形状,你指定为 3 x 3 阅读 the documentation 我可以看到你应该计算内角(黑色方块接触的地方)所以你的板实际上是 (14,6)