Issue 1:
System information (version)

OpenCV => 4.5.0

Operating System / Platform => Linux 64-bit

Compiler => / (python 3.8.6)

Detailed description

I am calling the stereoCalibrate function in my python code, but always throws assertion errors:

result = cv2.stereoCalibrate(objectPoints, imagePointsA, imagePointsB, intrA, distA, intrB, distB, (848, 480))

throws the following error:

error: OpenCV(4.5.0) /build/opencv/src/opencv-4.5.0/modules/calib3d/src/calibration.cpp:1088: error: (-215:Assertion failed) (count >= 4) || (count == 3 && useExtrinsicGuess) in function 'cvFindExtrinsicCameraParams2'

if I try adding the USE_EXTRINSIC_GUESS flag, it still fails:

result = cv2.stereoCalibrate(objectPoints, imagePointsA, imagePointsB, intrA, distA, intrB, distB, (848, 480), flags=cv2.CALIB_FIX_INTRINSIC+cv2.CALIB_USE_EXTRINSIC_GUESS)

throws the following error:

error: OpenCV(4.5.0) /build/opencv/src/opencv-4.5.0/modules/calib3d/src/calibration.cpp:3871: error: (-206:Bad flag (parameter or structure field)) stereoCalibrate does not support CALIB_USE_EXTRINSIC_GUESS. in function 'stereoCalibrate'

What is the problem? According to documentation I should be able to use the extrinsic guess, right?

Also, why am I getting an assertion error relating to number of object points (I guess), if I have 5704 object points in the array?

(count >= 4) || (count == 3 && useExtrinsicGuess) in function 'cvFindExtrinsicCameraParams2'

Steps to reproduce

I am passing the following arguments:

objectPoints -> python array, 5704 elements, where each looks like this:

array([[0.00375 , 0.09374999, 0. ]], dtype=float32) (numpy array of shape (1, 3))

'imagePointsA' and 'imagePointsB' -> python array, 5704 elements, each element looks like this:

array([[64.84993 , 28.067667]], dtype=float32) (numpy array of shape (1,2))

intrA and intrB -> numpy array, shape (3, 3). Looks like this:

array([[615.22052002, 0. , 431.19281006],
[ 0. , 615.42181396, 243.2046051 ],
[ 0. , 0. , 1. ]])

distA and distB -> numpy array, shape(5,), looks like this:

array([0., 0., 0., 0., 0.], dtype=float32)

Issue submission checklist

I report the issue, it's not a question

[ x] I checked the problem with documentation, FAQ, open issues,

answers.opencv.org, Stack Overflow, etc and have not found solution

[x ] I updated to latest OpenCV version and the issue is still there

There is reproducer code and related data files: videos, images, onnx, etc

Issue 2:
System information (version)

OpenCV => 3.4.2

Operating System / Platform => Raspbian Stretch

Python => 3.5.3

Detailed description

When adding the CALIB_USE_EXTRINSIC_GUESS flag, stereoCalibrate will fail the CV_IS_MAT tests. When calling the same method without that flag, and with same arguments it completes without issue. Also calling stereoCalibrateExtended works both with and without the USE_EXTRINISC_GUESS flag.

Not sure if this is related to #11085

Steps to reproduce

flags = cv2.CALIB_FIX_INTRINSIC
ret, mtx1, dist1, mtx2, dist2, R, T, E, F = cv2.stereoCalibrate(objpoints, imgpointsA, imgpointsB, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, grayA.shape[::-1], R=R, T=T, flags=flags, **kws)
flags += cv2.CALIB_USE_EXTRINSIC_GUESS
ret, mtx1, dist1, mtx2, dist2, R, T, E, F = cv2.stereoCalibrate(objpoints, imgpointsA, imgpointsB, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, grayA.shape[::-1], R=R, T=T, flags=flags, **kws)

Error output is:

cv2.error: OpenCV(3.4.2) /home/pi/opencv-3.4.2/modules/calib3d/src/calibration.cpp:1781: error: (-215:Assertion failed) (((_imagePoints1) != __null && (((const CvMat*)(_imagePoints1))->type & 0xFFFF0000) == 0x42420000 && ((const CvMat*)(_imagePoints1))->cols > 0 && ((const CvMat*)(_imagePoints1))->rows > 0) && ((const CvMat*)(_imagePoints1))->data.ptr != __null) && (((_imagePoints2) != __null && (((const CvMat*)(_imagePoints2))->type & 0xFFFF0000) == 0x42420000 && ((const CvMat*)(_imagePoints2))->cols > 0 && ((const CvMat*)(_imagePoints2))->rows > 0) && ((const CvMat*)(_imagePoints2))->data.ptr != __null) && (((_objectPoints) != __null && (((const CvMat*)(_objectPoints))->type & 0xFFFF0000) == 0x42420000 && ((const CvMat*)(_objectPoints))->cols > 0 && ((const CvMat*)(_objectPoints))->rows > 0) && ((const CvMat*)(_objectPoints))->data.ptr != __null) && (((_npoints) != __null && (((const CvMat*)(_npoints))->type & 0xFFFF0000) == 0x42420000 && ((const CvMat*)(_npoints))->cols > 0 && ((const CvMat*)(_npoints))->rows > 0) && ((const CvMat*)(_npoints))->data.ptr != __null) && (((matR) != __null && (((const CvMat*)(matR))->type & 0xFFFF0000) == 0x42420000 && ((const CvMat*)(matR))->cols > 0 && ((const CvMat*)(matR))->rows > 0) && ((const CvMat*)(matR))->data.ptr != __null) && (((matT) !=__null && (((const CvMat*)(matT))->type & 0xFFFF0000) == 0x42420000 && ((const CvMat*)(matT))->cols > 0 && ((const CvMat*)(matT))->rows > 0) && ((const CvMat*)(matT))->data.ptr != __null) in function 'cvStereoCalibrateImpl'

# This one does not fail
flags = cv2.CALIB_FIX_INTRINSIC
flags += cv2.CALIB_USE_EXTRINSIC_GUESS
cv2.stereoCalibrateExtended(objpoints, imgpointsA, imgpointsB, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, grayA.shape[::-1], R, T, flags=flags)