OpenCV“cv2.omnidir.calibrate”抛出断言错误

时间:2018-06-12 07:24:34

标签: python python-3.x opencv

我正在使用python 3.5.2和OpenCV 3.4.0开发Ubuntu 16.04。

我正在尝试使用OpenCV中的全向校准技术校准广角GoPro相机拍摄的图像。我试图在python中编写这个C++ omnidirectional calibration tutorial,但是我收到了一个Assertion错误。

这是我目前正在运行的代码:

#importing opencv, glob and numpy libraries
import cv2
import numpy as np
import glob
import imutils as im

#reading all JPEG images in current directory
images = glob.glob('*.jpg')

#criteria for refining corners
criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS, 30, 0.001)

#flags to control omnidir.calibrate and omnidir.undistortImage functions
calib_flag = cv2.omnidir.CALIB_USE_GUESS

#setting up grid for the 3D world points
nx = 9; ny = 6 
objp = np.zeros((nx*ny,3), np.float32)
objp[:,:2] = np.mgrid[0:nx,0:ny].T.reshape(-1,2)

#final list of world and image points
objpoints = []
imgpoints = []

for img_name in images :
    #reading images one by one and normalizing their image histograms 
    img = cv2.imread(img_name)
    img = im.resize(img, width = 1260)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    #finding chessboard corners in the image
    found, corners = cv2.findChessboardCorners(gray, (nx,ny), None)

    #if corners are found, append object points and refine the corners to append them to image points
    if found :
        objpoints.append(objp)

        #refining corners using subpixel gradients
        corners = cv2.cornerSubPix(gray, corners, (11,11), (-1,-1), criteria)
        corners = corners.reshape((54,2))    #because corners is (54,1,2) after cornerSubPix
        imgpoints.append(corners)

#trying to force the datatype to float64, comment out for float 32
imgpoints = np.array(imgpoints, dtype = np.float64)
objpoints = np.array(objpoints, dtype = np.float64)

print(imgpoints.shape,objpoints.shape)

#calibrating the camera using omnidirectional calibrate function
M = np.zeros((3,3))
dist_coeff = np.zeros((4,1))
xi = np.array([])
idx = np.array([])
ret, M, xi, dist_coeff, rVecs, tVecs, idx = cv2.omnidir.calibrate(objpoints, imgpoints, gray.shape[::-1], M, xi, dist_coeff, calib_flag, criteria)
#Assertion error in above line

以下是我在终端中运行代码时遇到的错误:

OpenCV Error: Assertion failed ((patternPoints.type() == (((6) & ((1 << 3) - 1)) + (((3)-1) << 3)) && imagePoints.type() == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3))) || (patternPoints.type() == (((5) & ((1 << 3) - 1)) + (((3)-1) << 3)) && imagePoints.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)))) in calibrate, file /home/pradyu/opencv_contrib-3.4.0/modules/ccalib/src/omnidir.cpp, line 1067

Traceback (most recent call last):

  File "omnicalib.py", line 54, in <module>

      ret, M, xi, dist_coeff, rVecs, tVecs, idx = cv2.omnidir.calibrate(objpoints, imgpoints, gray.shape[::-1], M, xi, dist_coeff, calib_flag, criteria)

cv2.error: /home/pradyu/opencv_contrib-3.4.0/modules/ccalib/src/omnidir.cpp:1067: error: (-215) (patternPoints.type() == (((6) & ((1 << 3) - 1)) + (((3)-1) << 3)) && imagePoints.type() == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3))) || (patternPoints.type() == (((5) & ((1 << 3) - 1)) + (((3)-1) << 3)) && imagePoints.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3))) in function calibrate

我检查了opencv-contrib模块源代码的第1067行中的断言,它应该是校准函数中图像和世界点的数据类型断言:世界点 - CV_64FC3(或32)和图像点 - CV_64FC2 (或32) 我已经确保相应的数组具有正确的类型和通道数,但错误仍然存​​在。

0 个答案:

没有答案