OpenCV 错误:断言失败 (nimages > 0 && nimages == (int)imagePoints1.tot ........3106行



OLD:尝试OpenCV教程进行相机校准
请在"编辑";在第一个python代码部分下方

我收到这个错误:

OpenCV Error: Assertion failed (nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total())) in collectCalibrationData, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/calib3d/src/calibration.cpp, line 3106
Traceback (most recent call last):
File "cse598a2.py", line 46, in <module>
None)
cv2.error: /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/calib3d/src/calibration.cpp:3106: error: (-215) nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total()) in function collectCalibrationData

我看到过类似的错误,但未能找到错误代码为3106的错误。31933415

我也试着寻找calibration.cpp文件,但在Ubuntu 18.04中找不到它,试图看看问题在哪里。尺寸确实如其他帖子所述。

这是我的代码

import cv2
import os
import numpy as np
import sys

path = os.path.expanduser('~') + '/catkin_ws/src/cse598a2/images/task_1'
entries = os.listdir(path)

object_points = np.zeros((6*9,3), np.float32)
object_points[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
objectt_points = [] # A 3d point in real world space
image_points = [] # for 2d points in image plane.
c = 0
for each in entries:
if c == 5: break;
if (each[0] == 'r'):
image = (cv2.imread(path + '/' + each))

image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
value_return, corners = cv2.findChessboardCorners(image_gray,
(6,9),
flags=cv2.CALIB_CB_FAST_CHECK)
if value_return:
objectt_points.append(object_points)
image_points.append(corners)

print len(objectt_points)
print len(image_points)
c = c + 1

#print (objectt_points)
#print (image_points)
# sys.exit(0)
value_return, matrix, dist, rvecs, tvecs = cv2.calibrateCamera(object_points,
image_points,
image_gray.shape[::-1],
None,
None)
height,  width = image_gray.shape[:2]
newcameramtx, region_interest = cv2.getOptimalNewCameraMatrix(mtx, dist, (width,height), 1, (width,height))
image_undistorted = cv2.undistort(image_gray, matrix, distance, None, newcameramtx)
x, y, width, height = region_interest
image_undistorted = image_undistorted[y:y+height, x:x+height]
print dist.shape

编辑:第二部分
这次,我无法解决问题。上一次,问题是我提供了一个错误的论点,这次,我先检查了一下,不明白问题出在哪里。我已经检查了代码示例来查看方法。堆栈溢出的立体声校准示例这是错误

OpenCV Error: Assertion failed (nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total())) in collectCalibrationData, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/calib3d/src/calibration.cpp, line 3106
Traceback (most recent call last):
File "cse598a2_t2.py", line 81, in <module>
flags=cv2.CALIB_FIX_INTRINSIC))
cv2.error: /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/calib3d/src/calibration.cpp:3106: error: (-215) nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total()) in function collectCalibrationData
import cv2
import os
import numpy as np
import sys

path = os.path.expanduser('~') + '/catkin_ws/src/cse598a2/images/task_2'
entries = os.listdir(path)

object_file_storage_L = cv2.FileStorage('camera_L.yml', flags=cv2.FILE_STORAGE_READ)
object_file_storage_R = cv2.FileStorage('camera_R.yml', flags=cv2.FILE_STORAGE_READ)
dis_L = object_file_storage_L.getNode('cam_L_dispar').mat()
dis_R = object_file_storage_R.getNode('cam_R_dispar').mat()
mat_L = object_file_storage_L.getNode('cam_L_matrix').mat()
mat_R = object_file_storage_R.getNode('cam_R_matrix').mat()
object_file_storage_L.release()
object_file_storage_R.release()

object_points = np.zeros((6*9,3), np.float32)
object_points[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
objectt_points = [] # A 3d point in real world space
image_points_L = [] # for 2d points in image plane.
image_points_R = [] # for 2d points in image plane.
file_l0 = 'left_0.png'
file_l1 = 'left_1.png'
file_r0 = 'right_0.png'
file_r1 = 'right_1.png'
image = cv2.imread(path + '/' + file_l0)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
value_return, corners = cv2.findChessboardCorners(image_gray, (6, 9), flags=cv2.CALIB_CB_FAST_CHECK)
print corners.shape
if value_return:
objectt_points.append(object_points)
image_points_L.append(corners)
image = cv2.imread(path + '/' + file_l1)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
value_return, corners = cv2.findChessboardCorners(image_gray, (6, 9), flags=cv2.CALIB_CB_FAST_CHECK)
print corners.shape
if value_return:
objectt_points.append(object_points)
image_points_L.append(corners)
image = cv2.imread(path + '/' + file_r0)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
value_return, corners = cv2.findChessboardCorners(image_gray, (6, 9), flags=cv2.CALIB_CB_FAST_CHECK)
print corners.shape
if value_return:
objectt_points.append(object_points)
image_points_L.append(corners)
image = cv2.imread(path + '/' + file_r1)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
value_return, corners = cv2.findChessboardCorners(image_gray, (6, 9), flags=cv2.CALIB_CB_FAST_CHECK)
print corners.shape
if value_return:
objectt_points.append(object_points)
image_points_L.append(corners)
retval, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = (
cv2.stereoCalibrate(objectt_points,
image_points_L,
image_points_R,
mat_L,
dis_L,
mat_R,
dis_R,
image_gray.shape,
flags=cv2.CALIB_FIX_INTRINSIC))

这是与
cameraCalibration()
相关的第一部分的解决方案没关系,我想我找到了。我为函数calibrateCamera()提供的参数有问题

现在,在2021年2月21日的EDIT下出现了一个新问题。

EDIT的解决方案,问题第2部分

代码有错误,并且有一个轻微的概念问题。CCD_ 2从未被填充并且全部被附加到CCD_ 3。概念上的问题是不需要附加4倍的3D坐标,因为单个时间帧的L和R凸轮都对应于相同的坐标。

注释行60和69,更正行61和70

相关内容

  • 没有找到相关文章

最新更新