所以我用相机拍了一堆照片并按照这里发布的教程:http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html
但是我遇到了问题。我从drawchessboardcorners函数中得到一张空图像,我不确定为什么。注意我是opencv的新手,所以对某些人来说这可能是微不足道的,但现在我无法弄明白。我使用的是opencv 2.4.10。
代码:
import numpy as np
import cv2
# 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.
for i in range (1,13):
img = cv2.imread('calibrate/calibrate' + str(i) + '.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (9,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(corners)
# Draw and display the corners
img = cv2.drawChessboardCorners(img, (9,6), corners2,ret)
cv2.imshow('img',img)
cv2.waitKey(500)
else:
print "No Calibration"
cv2.destroyAllWindows()
这是我网络摄像头拍摄的照片:
这是错误代码的图片:
我修改了一些代码以处理我拍摄的照片(使用我编写的程序)。例如,for循环只是因为我有12张照片,其名称如calibrate1,calibrate2等等。我非常难过这个,希望你们中的一个能给我见解!感谢
答案 0 :(得分:0)
所以在@berak的评论之后我决定卸载opencv 2.4并安装opencv 3.0,看看上面的代码是有效的!谢谢@berak