Skip to content

Python stereoCalibrate fails assertion when adding CALIB_USE_EXTRINSIC_GUESS flag #12012

Closed

Description

@qenops
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)

Activity

  1. alalek commented on Jul 19, 2018

    @alalek
    Member

    Please add dump (via Python print/pprint) of all passed matrices or at least their "shape".

  2. qenops commented on Jul 19, 2018

    @qenops
    Author

    Here is the data I'm using:

    objpoints = list of 9 ndarray of shape 54,3 with dtype np.float32
    imgpointsA = list of 9 ndarray of shape 54,1,2 with dtype np.float32
    imgpointsB = list of 9 ndarray of shape 54,1,2 with dtype np.float32
    cameraMatrix1 = np.array([[ 407.87383762,0.,322.49729584],[0.,407.96003123,247.6930031],[0.,0.,1.]],dtype=np.float64)
    distCoeffs1 = np.array([[ -4.16483960e-01],[  2.08322274e-01],[  2.77542975e-04],[ -5.90362926e-04],[ -5.70882963e-02]],dtype=np.float64)
    cameraMatrix2 = np.array([[ 387.06322646,0.,315.62728327],[0.,387.82902342,254.41221478],[0.,0.,1.]],dtype=np.float64)
    distCoeffs2 = np.array([[-0.40212671],[ 0.19521368],[ 0.00196181],[-0.00042008],[-0.05139762]],dtype=np.float64)
    imageSize = (640,480)
    R = np.array([[9.52021185e-01,-9.30718068e-03,3.05890567e-01],[8.74371643e-03,9.99956614e-01,3.21217358e-03],[ -3.05907192e-01,-3.83436919e-04,9.52061260e-01]],dtype=np.float64)
    T = np.array([[-63.78115762],[ -0.85865368],[ 16.71733832]],dtype=np.float64)
  3. marcozmonteiro commented on Jul 24, 2018

    @marcozmonteiro

    I've also encountered this issue. Using suggestion from @qenops, switched to stereoCalibrateExtended and it did work passing R and T.

  4. alalek commented on Jul 24, 2018

    @alalek
    Member

    I added some dumpers for OpenCV's InputArray/InputArrayOfArrays function's parameters: #12054
    It would be nice to dump metadata of your arguments via these functions?

    Try to split assertion line (to get exact parameter name with problem):

    -     CV_Assert( CV_IS_MAT(_imagePoints1) && CV_IS_MAT(_imagePoints2) &&
    -               CV_IS_MAT(_objectPoints) && CV_IS_MAT(_npoints) &&
    -               CV_IS_MAT(matR) && CV_IS_MAT(matT) );
    +    CV_Assert(CV_IS_MAT(_imagePoints1));
    +    CV_Assert(CV_IS_MAT(_imagePoints2));
    +    CV_Assert(CV_IS_MAT(_objectPoints));
    +    CV_Assert(CV_IS_MAT(_npoints));
    +    CV_Assert(CV_IS_MAT(matR));
    +    CV_Assert(CV_IS_MAT(matT));
  5. qenops commented on Aug 3, 2018

    @qenops
    Author

    Sorry it took a while to circle back to this. It looks like matR is causing the problem:

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

  6. qenops commented on Aug 3, 2018

    @qenops
    Author

    Output of the new tests is:

    ======================================================================
    FAIL: test_InputArray (test_misc.Arguments)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/pi/opencv-3.4.2/modules/python/test/test_misc.py", line 52, in test_InputArray
        self.assertEqual(res1, "InputArray: empty()=true kind=0x00010000 flags=0x01010000 total(-1)=0 dims(-1)=0 size(-1)=0x0 type(-1)=CV_8UC1")
    AssertionError: 'Inpu[23 chars]nd=0x100200010000 flags=0x01010000 total(-1)=0[37 chars]8UC1' != 'Inpu[23 chars]nd=0x00010000 flags=0x01010000 total(-1)=0 dim[33 chars]8UC1'
    - InputArray: empty()=true kind=0x100200010000 flags=0x01010000 total(-1)=0 dims(-1)=0 size(-1)=0x0 type(-1)=CV_8UC1
    ?                                 ----
    + InputArray: empty()=true kind=0x00010000 flags=0x01010000 total(-1)=0 dims(-1)=0 size(-1)=0x0 type(-1)=CV_8UC1
    
    
    ======================================================================
    FAIL: test_InputArrayOfArrays (test_misc.Arguments)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/pi/opencv-3.4.2/modules/python/test/test_misc.py", line 70, in test_InputArrayOfArrays
        self.assertEqual(res1, "InputArrayOfArrays: empty()=true kind=0x00050000 flags=0x01050000 total(-1)=0 dims(-1)=1 size(-1)=0x0")
    AssertionError: 'Inpu[31 chars]nd=0x100200050000 flags=0x01050000 total(-1)=0[20 chars]=0x0' != 'Inpu[31 chars]nd=0x00050000 flags=0x01050000 total(-1)=0 dim[16 chars]=0x0'
    - InputArrayOfArrays: empty()=true kind=0x100200050000 flags=0x01050000 total(-1)=0 dims(-1)=1 size(-1)=0x0
    ?                                         ----
    + InputArrayOfArrays: empty()=true kind=0x00050000 flags=0x01050000 total(-1)=0 dims(-1)=1 size(-1)=0x0
    

    If I update the kind values in the unit test to 0x100200010000 and 0x100200050000, it passes all tests in the Arguments class.

  7. alalek commented on Aug 3, 2018

    @alalek
    Member

    It seems failed Python test is my mistake (invalid format: expects "long long int", passed "int" only - garbage is printed).

    Please add dump of these statements (right before stereoCalibrate call):

    • print(cv.utils.dumpInputArray(R))
    • print(cv.utils.dumpInputArray(cameraMatrix1))
  8. qenops commented on Aug 3, 2018

    @qenops
    Author
    >>> print(cv2.utils.dumpInputArray(cam.R))
    InputArray: empty()=false kind=0x100200010000 flags=0x01010000 total(-1)=9 dims(-1)=2 size(-1)=3x3 type(-1)=CV_64FC1
    >>> print(cv2.utils.dumpInputArray(cam.lfMatrix))
    InputArray: empty()=false kind=0x100200010000 flags=0x189f35801010000 total(-1)=9 dims(-1)=2 size(-1)=3x3 type(-1)=CV_64FC1
    
  9. alalek commented on Aug 3, 2018

    @alalek
    Member

    stereoCalibrateExtended has this declaration of R/T parameters:

    InputOutputArray R,InputOutputArray T

    stereoCalibrate has this:

    OutputArray R,OutputArray T

    There is no way to pass initial values of R/T into stereoCalibrate() call.
    So CALIB_USE_EXTRINSIC_GUESS can be used with stereoCalibrateExtended() only.

    Need to add check with more adequate error message.

  10. added 3 commits that reference this issue on Oct 3, 2018
    4788a3b
    61266b1
    68e6718
  11. added a commit that references this issue on Jul 30, 2026
    f42f68f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions