我使用下面的代碼來找到國際象棋棋盤上的角落 ,但是當我運行它時,我什麼都沒有顯示圖像 並沒有顯示角落已被發現,儘管在頁面opencv他們說應該出現一個圖像。python和opencv的校準
import numpy as np
import cv2
import glob
# 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((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,0:6].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, (7,6),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, (7,6), corners2,ret)
cv2.imshow('img',img)
cv2.waitKey(500)
cv2.destroyAllWindows()
下面是我使用的電路板圖像:
我檢查了圖像已經加載,我嘗試了其他圖像,但仍然有相同的結果! – Sabrine
您可以添加您在問題中使用的圖像嗎? – AldurDisciple
好的,你應該看看OpenCV校準教程(http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html#cameracalibrationopencv)。嘗試使用原始棋盤圖像進行校準是沒有意義的。基本上,您需要打印棋盤圖像,將其粘貼在一塊木頭上,然後使用相機觀察它以校準相機。 – AldurDisciple