Python OpenCV 立体相机校准阵列错误:TypeError:不支持 imagePoints1 数据类型 = 17

Posted

技术标签:

【中文标题】Python OpenCV 立体相机校准阵列错误:TypeError:不支持 imagePoints1 数据类型 = 17【英文标题】:Python OpenCV Stereo Camera Calibration Array Error: TypeError: imagePoints1 data type = 17 is not supported 【发布时间】:2015-12-03 16:34:53 【问题描述】:

我正在使用立体相机设置进行凝视校正项目。对于我设计的算法,我需要校准相机并纠正图像。我也想实时做到这一点。我在尝试使用 cv2.stereoCalibrate 方法时遇到了一个错误,我进行了广泛的搜索并阅读了官方文档,但没有一个能够帮助我,即使在我修改了几次代码之后也是如此。

这里是:

import cv2
import numpy as np
import Camera

def calibrate(camera1, camera2):
    if(isinstance(camera1, Camera.Camera) & isinstance(camera2, Camera.Camera)):
        pass
    else:
        raise ValueError( "Wrong input types. Expecting: <Camera>, <Camera> \n Got: <" + 
                      str(camera1.__class__) +'>, <' + str(camera2.__class__) +'>.\n')  
    #instantiate Real-world object point matrix
    objPoints = np.zeros(((9*6), 3), np.int32)
    objPoints[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)

    #Chessboard pattern dimesntions
    dims = (9, 6)

    #2 arrays to store 3D and 2D object points
    objPArray = []
    imgPArrayr = []
    imgPArrayl = []

    #some useful matrices
    R = [] # rotation matrix 
    T = [] # translation vector beterwwn coordinate systems
    E = [] # essential matrix
    F = [] #fundamental matrix
    Q = [] #disparity to depth mapping matrix

    criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,
                100, 1e-5)
    flags = (cv2.CALIB_FIX_ASPECT_RATIO + cv2.CALIB_ZERO_TANGENT_DIST +
             cv2.CALIB_SAME_FOCAL_LENGTH + cv2.CALIB_FIX_INTRINSIC)

    ret,imgr  = camera1.read()
    ret,imgl  = camera2.read()

    #Converting to greyscale, as OpenCV requires it for calibration
    grey_imgr = cv2.cvtColor(imgr, cv2.COLOR_BGRA2GRAY)
    grey_imgl = cv2.cvtColor(imgl, cv2.COLOR_BGRA2GRAY)


    ret, cornersr =cv2.findChessboardCorners(grey_imgr,dims)
    cv2.drawChessboardCorners(grey_imgr, dims,cornersr,0)

    ret, cornersl =cv2.findChessboardCorners(grey_imgl,dims)
    cv2.drawChessboardCorners(grey_imgl, dims, cornersl,0)

    cv2.imshow("chessboard", grey_imgr)
    cv2.imshow("chessboard1", grey_imgl)

    imgPArrayl.append(cornersl)
    imgPArrayr.append(cornersr)
    objPArray.append(objPoints)
    '''
    cv2.imwrite("./test_images/img_r"+str(i)+".jpg",imgr)
    cv2.imwrite("./test_images/img_l"+str(i)+".jpg",imgl)
    i+=1
    '''

    objPArray = [np.asarray(x) for x in objPArray]
    imgPArrayl = [np.asarray(x) for x in imgPArrayl]
    imgPArrayr = [np.asarray(x) for x in imgPArrayr]

    print imgPArrayl
    print imgPArrayr

    retvalCalib, cameraMatrixl, distCoeffsl, cameraMatrixr, distCoeffsr, R, T, E, F =\
        cv2.stereoCalibrate(objPArray,
                            imgPArrayl,
                            imgPArrayr,
                            (9*6),
                            None,
                            None,
                            None,
                            None,
                            (640,480),
                            criteria,
                            flags)

    return retvalCalib, cameraMatrixl, distCoeffsl, cameraMatrixr, distCoeffsr, R, T, E, F

我得到的错误是: TypeError: imagePoints1 data type = 17 is not supported

我该怎么办?

【问题讨论】:

可能你提供了一些额外的信息:OpenCV版本,python版本,你做了哪些努力?显然,在您的情况下,cv2.stereoCalibrate 不接受您的点数组之一 (imgPArrayl),但我无法使用 OpenCV 3.0.0 重现此错误。 OpenCV3 与 Python 2.7 。我查看了文档,并尝试了将各种不同的参数传递给函数。我还更改了数组单元格的变量定义(在 np.int/float/double/32/64 之间) 【参考方案1】:

从源代码重新编译 OpenCV3 并重新安装它可以消除此问题。

【讨论】:

以上是关于Python OpenCV 立体相机校准阵列错误:TypeError:不支持 imagePoints1 数据类型 = 17的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV 立体匹配/校准

无目标非重叠立体相机校准

OpenCV中的相机失真内外参不失真图像相机校准

OpenCV - Python 断言错误:SAD 算法 - 立体相机视差图计算

使用立体相机从视差图进行深度重建

在线校准相机中校准相机时出现 OpenCV 运行时错误