Ask Your Question
0

Assertion failed i < 0, in calibrateCamera()

asked 2016-04-12 21:47:42 -0600

user_12 gravatar image

I am getting following error message

OpenCV Error: Assertion failed (i < 0) in create, file /tmp/OpenCV-2.4.0/modules/core/src/matrix.cpp, line 1335 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/OpenCV-2.4.0/modules/core/src/matrix.cpp:1335: error: (-215) i < 0 in function create

while running my code:

What will be possible reasons for this error ?

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

IplImage* src = NULL;

void get2d3dPairs(string fileName,  vector<Point2f> & imgPts, vector<Point3f> & objPts, float z)
{
  //hard coded values; 
  imgPts.push_back(Point2f(144.00,  1011.0));       
  imgPts.push_back(Point2f(237.00,  801.0));     
  imgPts.push_back(Point2f(242.00,  583.0));
  imgPts.push_back(Point2f(271.00,  421.0));
  imgPts.push_back(Point2f(632.00,  1009.0));
  imgPts.push_back(Point2f(607.00,  820.0));
  imgPts.push_back(Point2f(634.00,  600.0));
  imgPts.push_back(Point2f(612.00,  428.0));
  imgPts.push_back(Point2f(1104.00, 1011.0));
  imgPts.push_back(Point2f(1095.00, 837.0));
  imgPts.push_back(Point2f(1107.00, 614.0));
  imgPts.push_back(Point2f(1063.00, 443.0));

  objPts.push_back(Point3f(18.00, 18.00, 0));
  objPts.push_back(Point3f(25.00, 110.00, 0));
  objPts.push_back(Point3f(26.00, 226.00, 0));
  objPts.push_back(Point3f(29.00, 327.00, 0));
  objPts.push_back(Point3f(94.00, 22.00, 0));
  objPts.push_back(Point3f(92.00, 106.00, 0));
  objPts.push_back(Point3f(98.00, 222.00, 0));
  objPts.push_back(Point3f(97.00, 325.00, 0));
  objPts.push_back(Point3f(168.00,  26.00, 0));
  objPts.push_back(Point3f(174.00,  104.0, 0));
  objPts.push_back(Point3f(187.00,  220.0, 0));
  objPts.push_back(Point3f(187.00, 323.00, 0));
  return;
}

int main(int argc, char ** argv)
{
  vector<Point2f> img20, img40, img60, img80;
  vector<Point3f> obj20, obj40, obj60, obj80;

  get2d3dPairs("points_Test_20cm.txt", img20, obj20, 20);
  get2d3dPairs("points_Test_40cm.txt", img40, obj40, 40);
  get2d3dPairs("points_Test_60.txt", img60, obj60, 60);
  get2d3dPairs("points_Test_80cm.txt", img80, obj80, 80);

  vector<vector<Point2f> > imPts;
  vector<vector<Point3f> > obPts;

  imPts.push_back(img20);
  imPts.push_back(img40);
  imPts.push_back(img60);
  imPts.push_back(img80);

  obPts.push_back(obj20);
  obPts.push_back(obj40);
  obPts.push_back(obj60);
  obPts.push_back(obj80);

#if 1
  Mat distortionCoef(4,1,  DataType<double>::type);
  distortionCoef.at<double>(0) = 0;
  distortionCoef.at<double>(1) = 0;
  distortionCoef.at<double>(2) = 0;
  distortionCoef.at<double>(3) = 0;
#endif
  Size imSize(1280, 1024);
  Mat cameraMatrix = initCameraMatrix2D(obPts, imPts, imSize, 0);
  cout << "CamMatrix: " << cameraMatrix << endl;
  Mat rvec, tvec;
  calibrateCamera(obPts, imPts, imSize, cameraMatrix, distortionCoef, rvec, tvec);
}
edit retag flag offensive close merge delete

Comments

how did you solve this problem?

german_iris gravatar imagegerman_iris ( 2016-05-27 06:31:38 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2019-07-05 11:45:13 -0600

a739 gravatar image

We need to give rvec and tvec as vector<cv::Mat>

In the sample code rvec and tvec is of cv::Mat

Source: https://stackoverflow.com/a/36605425

The error can also happen if obPts or imPts have the wrong dimension. They should be "a vector of vectors of" points.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-12 21:47:42 -0600

Seen: 439 times

Last updated: Jul 05 '19