我收到此错误,我无法解决此错误。 我猜该错误与优化模块有关,是由输入向量的类型引起的。 但我无法解决! 请给我一个解决方案。
cv2版本为3.1.0 python 3.5
import cv2
assert cv2.__version__[0] == '3', 'The fisheye module requires opencv version >= 3.0.0'
import numpy as np
import os
CHECKERBOARD = (6,9)
subpix_criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
calibration_flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC+cv2.fisheye.CALIB_CHECK_COND+cv2.fisheye.CALIB_FIX_SKEW
objp = np.zeros((1, CHECKERBOARD[0]*CHECKERBOARD[1], 3), np.float32)
objp[0,:,:2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2)
_img_shape = None
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.
images = glob.glob('*.jpg')
pict_dir = './pics/chess_boads_2/fish_eye/'
images = [ pict_dir + f for f in os.listdir(pict_dir) if "JPG" in f][:1]
for fname in images:
img = cv2.imread(fname)
img = cv2.resize(img, (500,500))
if _img_shape == None:
_img_shape = img.shape[:2]
else:
assert _img_shape == img.shape[:2], "All images must share the same size."
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_FAST_CHECK+cv2.CALIB_CB_NORMALIZE_IMAGE)
print("->",ret)
# If found, add object points, image points (after refining them)
if ret == True:
objpoints.append(objp)
corners = cv2.cornerSubPix(gray,corners,(3,3),(-1,-1),subpix_criteria)
imgpoints.append(corners)
img = cv2.drawChessboardCorners(img, (6,9), corners,ret)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
N_OK = len(objpoints)
K = np.zeros((3, 3))
D = np.zeros((4, 1))
D = np.zeros(4)
rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)]
tvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)]
rms, _, _, _, _ = \
cv2.fisheye.calibrate(
objpoints,
imgpoints,
gray.shape[::-1],
K,
D
)
print("Found " + str(N_OK) + " valid images for calibration")
print("DIM=" + str(_img_shape[::-1]))
print("K=np.array(" + str(K.tolist()) + ")")
print("D=np.array(" + str(D.tolist()) + ")")
-> True
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-5-f52039dc56d0> in <module>()
62 gray.shape[::-1],
63 K,
---> 64 D
65 )
66
error: ..\..\..\modules\core\src\arithm.cpp:639: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function cv::arithm_op'
我反复更改了代码。并且我发现错误发生在cv2.fisheye.calibrate()中。 但我不知道该如何解决。