Hi,
I have been trying to use the Omnidirectional camera model for stereo rectification, but even when just following the tutorial with the provided .xml I get a "Assertion failed".
The call that invokes this error is this one:
double rms = cv::omnidir::stereoCalibrate(objectPoints, imagePoints1, imagePoints2, imgSize1, imgSize2, K1, xi1, D1, K2, xi2, D2, rvec, tvec, rvecsL, tvecsL, flags, critia, idx);
The variables were set just like the tutorial on "modules/ccalib/tutorial/omnidir_tutorial.md" using the .xml on the "modules/ccalib/tutorial/data/" folder.
The full error message is this:
OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create, file /var/tmp/portage/media-libs/opencv-3.1.0-r4/work/opencv-3.1.0/modules/core/src/matrix.cpp, line 2232
terminate called after throwing an instance of 'cv::Exception'
what(): /var/tmp/portage/media-libs/opencv-3.1.0-r4/work/opencv-3.1.0/modules/core/src/matrix.cpp:2232: error: (-215) !fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows) in function create
I am using the opencv-3.1.0-r4 on a Gentoo.
Any ideas how to go around this error?
Hello! I'm also receiving this error. I also tried to initialize the function's arguments in many different ways.
Did you manage to solve the issue since then?
Hi, @kurohi and @kristofvarszegi , I am the author of omnidir calibration toolbox. It indeed a bug, change the 1309 line of omnidir.cpp to
om.create(3, 1, CV_64F);
T.create(3, 1, CV_64F);
will fix it.
If you have more questions, please inform me
Thank you very much for the answer!
Works for me as well, thank you for the fix!
I am getting the same error when trying to call calibrate() using Pything bindings.
K = np.zeros((3, 3))
D = np.zeros((4, 1))
xi = np.zeros(1)
ret = cv2.omnidir.calibrate(
objpoints,
imgpoints,
shape,
K,
xi,
D,
cv2.omnidir.CALIB_FIX_SKEW,
(cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6),
)
I am experiencing the exact same issues as @rnbdev using the python bindings of OpenCV 4.3.1:
OpenCV(3.4.1) Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create, file /usr/local/src/opencv/modules/core/src/matrix_wrap.cpp, line 1240
I seems to have to do with the way the python wrapper allocates optional parameters, which is incompatible with the way the stereo calibration prepares it return values.
I hope I will find some time to investigate this issue further in the next few weeks.
@jiuerbujie: Any insight in what might cause this?
Same issue as @rnbdev and @FlorianFranzen ... any solutions?
Fourthed, same issue as others with the python binding when calibrating. @FlorianFranzen @pcp16 @rnbdev
I had an array the wrong shape. The following works if anybody else ends up here:
K = np.zeros((3, 3))
D = np.zeros([1, 4])
xi = np.zeros(1)
calibration_flags = cv2.omnidir.CALIB_FIX_SKEW + cv2.omnidir.CALIB_USE_GUESS
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6)
rms = \
cv2.omnidir.calibrate(
objpoints,
imgpoints,
gray.shape[::-1],
K,
xi,
D,
calibration_flags,
criteria)
where objpoints is a list of numpy arrays, all with shape (1, checkboard_num, 3)
@benDavidson6 You do not seem to run stereoCalibrate, so your results are irrelevant to at least this bug.
@jiuerbujie Might the patch you proposed be the reason that OpenCV now tries to resize some fixed size matrices when running the python bindings?
Hi, @kurohi and @kristofvarszegi , I am the author of omnidir calibration toolbox. It indeed a bug, change the 1309 line of omnidir.cpp to
om.create(3, 1, CV_64F); T.create(3, 1, CV_64F);will fix it.
If you have more questions, please inform me
For me, i got the same issue with the OpenCV python bindings while using the calibrateStereo function. It always fails with an assertion failed and the following error message:
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\core\src\matrix_wrap.cpp:1236: error: (-215:Assertion failed) !fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows) in function 'cv::_OutputArray::create'
@jiuerbujie, @alalek Is there any fix for this problem available? I would really appreciate that.
Best regards, Patrick