Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python findChessboardCorners无法找到超过3x3的棋盘_Python_Opencv_Camera Calibration - Fatal编程技术网

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

Python findChessboardCorners无法找到超过3x3的棋盘,python,opencv,camera-calibration,Python,Opencv,Camera Calibration,我正在尝试使用棋盘法校准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) ....

我正在尝试使用棋盘法校准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)

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

ret, corners = cv2.findChessboardCorners(gray, (14,6),None)
中的
(x,y)

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

cv2.findChessboardCorners(gray, (x,y),None)
是板的形状,指定为3乘3
阅读我可以看到你应该计算内角(黑色方块接触的地方),所以你的棋盘实际上是
(14,6)

它找到了3号,因为你告诉我要找到3号
cv2.findChessboardCorners(灰色,(x,y),无)
那是你棋盘的形状(x,y)我用x和y来表示图案大小,到目前为止,3x3是我找到的唯一方法,我用3x4,4x3等等来尝试。你的棋盘是14乘6(或6乘14)。你数一数内角(黑色方块接触的地方)就是医生页面耶,你是对的,我很笨。我没有试过14x6,只是玩了一下图案尺寸,谢谢你帮我找到了3号,因为你告诉我要找到3号
cv2.findChessboardCorners(灰色,(x,y),无)
那是你棋盘的形状(x,y)我用x和y来表示图案大小,到目前为止,3x3是我找到的唯一方法,我用3x4,4x3等等来尝试。你的棋盘是14乘6(或6乘14)。你数一数内角(黑色方块接触的地方)就是医生页面耶,你是对的,我很笨。我没有尝试14x6,只是玩了一下图案大小,谢谢你的帮助。