question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StereoCalibrate Error i < 0

See original GitHub issue

Summary of your issue

I’m attempting to run StereoCalibrate on the left/right calibration images in the example data. I can calibrate each camera separately but I get this very undescriptive error ( i < 0 ) when moving on to the StereoCalibrate function. There’s a good probability that one of my inputs isn’t right, but I have no way of knowing which one. From what I can tell, all inputs are the correct type and size. Nothing is empty.

Environment

Windows 10, x64

What did you do when you faced the problem?

Checked to make sure all input lists of points are the correct size, not empty or null.

Example code:

` // images contains a list of pairs of left/right images var objectPointsOfFrames = new List<InputArray>(images.Count);

        var leftImagePointsOfFrames = new List<InputArray>(images.Count);
        var rightImagePointsOfFrames = new List<InputArray>(images.Count);

        var frameSize = images.First().Item1.Size();

        foreach (var imagePair in images)
        {
            // I can confirm that each image contains a chessboard pattern and returns points
            leftImagePointsOfFrames.Add(chessBoard.FindFromImage(imagePair.Item1));
            rightImagePointsOfFrames.Add(chessBoard.FindFromImage(imagePair.Item2));

            // This adds a MatOfPoint3f with the points in the chess pattern
            objectPointsOfFrames.Add(chessBoard.GetObjectMatPoints());
        }

        var essentialMatrix = new Mat();
        var fundamentalMatrix = new Mat();

          // LeftCam.CamMatrix, LeftCam.DistortionCoefficients are configured from successfully calibrating from the left image set.  The same applies to RightCam.
          Cv2.StereoCalibrate(
                objectPointsOfFrames,
                leftImagePointsOfFrames,
                rightImagePointsOfFrames,
                LeftCam.CamMatrix, LeftCam.DistortionCoefficients,
                RightCam.CamMatrix, RightCam.DistortionCoefficients,
                frameSize, RotationVector, TranslationVector, essentialMatrix, fundamentalMatrix);

`

Output:

OpenCvSharp.OpenCVException: i < 0 at OpenCvSharp.NativeMethods+<>c.<.cctor>b__1619_0 (OpenCvSharp.ErrorCode status, System.String funcName, System.String errMsg, System.String fileName, System.Int32 line, System.IntPtr userdata) [0x00010] in <45a494b8b9514a01b4c3f460652ae2ad>:0 at (wrapper managed-to-native) OpenCvSharp.NativeMethods.calib3d_stereoCalibrate_InputArray(intptr[],int,intptr[],int,intptr[],int,intptr,intptr,intptr,intptr,OpenCvSharp.Size,intptr,intptr,intptr,intptr,int,OpenCvSharp.TermCriteria) at OpenCvSharp.Cv2.StereoCalibrate (System.Collections.Generic.IEnumerable1[T] objectPoints, System.Collections.Generic.IEnumerable1[T] imagePoints1, System.Collections.Generic.IEnumerable1[T] imagePoints2, OpenCvSharp.InputOutputArray cameraMatrix1, OpenCvSharp.InputOutputArray distCoeffs1, OpenCvSharp.InputOutputArray cameraMatrix2, OpenCvSharp.InputOutputArray distCoeffs2, OpenCvSharp.Size imageSize, OpenCvSharp.OutputArray R, OpenCvSharp.OutputArray T, OpenCvSharp.OutputArray E, OpenCvSharp.OutputArray F, OpenCvSharp.CalibrationFlags flags, System.Nullable1[T] criteria) [0x0010c] in <45a494b8b9514a01b4c3f460652ae2ad>:0

What did you intend to be?

Not an exception 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
jwheeler-unitycommented, Mar 23, 2019

Here’s my code, I hope it helps:

        var objectPointsOfFrames = new List<List<Point3f>>(images.Count);

        var leftImagePointsOfFrames = new List<List<Point2f>>(images.Count);
        var rightImagePointsOfFrames = new List<List<Point2f>>(images.Count);

        foreach (var imagePair in images)
           // Get all the points
       
        try
        {
            var essentialMatrix = new Mat();
            var fundamentalMatrix = new Mat();

            Cv2.StereoCalibrate(
                objectPointsOfFrames,
                leftImagePointsOfFrames,
                rightImagePointsOfFrames,
                LeftCamera.CameraMatrixDoubles, LeftCamera.DistortionCoefficentsDoubles,
                RightCamera.CameraMatrixDoubles, RightCamera.DistortionCoefficentsDoubles,
                frameSize, // end inputs
                RotationVector, TranslationVector, essentialMatrix, fundamentalMatrix);
0reactions
stale[bot]commented, Sep 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenCV stereoCalibrate returns high RMS error
i have some problems while computing rectification of stereo pairs with OpenCV: stereoCalibrate returns an high rms error and i obtain bad ...
Read more >
abs_max < threshold in function 'stereoCalibrate'
Hi,. I had a stereo calibration pipeline built for regular (non fisheye) lenses that was working just fine (based on cv2.stereoCalibrate() ...
Read more >
Stereo_Camera Calibration error
Hi, I am running the Stereo Pi Fisheye tutorial. I am on part 4, the calibration. I seem to calibrate both individual cameras...
Read more >
OpenCV stereoCalibrate returns high RMS error-Opencv
I solved the problem by checking the found chessboard patterns and removing the image pairs where the pattern is detected in different order....
Read more >
cv.stereoCalibrate - mexopencv
Calibrates the stereo camera. S = cv.stereoCalibrate(objectPoints, imagePoints1, imagePoints2, imageSize) [...] = cv.stereoCalibrate(..., 'OptionName' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found