CV2 plotChessboardCorners和cornersSubPix所期望的点的形状/顺序是什么?

时间:2016-08-11 18:33:44

标签: opencv

我试图将一系列点数传递给plotChessboardCorners和cornersSubPix函数,但我收到这些错误消息:

Exception: ..\..\..\..\opencv\modules\calib3d\src\calibinit.cpp:1944:
error: (-215) nelems >= 0 in function cv::drawChessboardCorners

Exception: ..\..\..\..\opencv\modules\imgproc\src\cornersubpix.cpp:257: 
error: (-215) ncorners >= 0 && corners.depth() == CV_32F in function cv::cornerSubPix

我认为这与数组的排序有关。但是,findChessboardCorners返回一个shape [npoints,1,2]的数组,它与我传递的数组的形状相同?

我的代码是:

                if (findChessboardCorners failed):
                    corners = (reconstructed corners of shape [npoints, 2])
                    corners.shape = (len(corners),1,2) #reshape to shape expected by openCV
                    numfound = 0 if corners is None else len(corners) 

                    if numfound==nX*nY: #reconstruction successful
                        figC = plt.figure('Corners found in image ' +str(i+1) + ' in camera ' +camnames[j])                
                        plt.imshow(I, cmap='gray')
                        cv2.drawChessboardCorners(Inew, (nX,nY), corners, 1)
                        plt.show()   

1 个答案:

答案 0 :(得分:2)

这是一个数据类型问题:corner数组需要是float32。 此断言语句生成错误消息: int nelems = corners.checkVector(2, CV_32F, true); CV_Assert(nelems >= 0);