0

I'm looking at camera calibration sample code in opencv.

Now, I'm troubling with understanding some lines of the code. This code is in the sample code folder in Opencv 2.4.3.

My question is about C++ rather than opencv.

Here is the sample code in opencv.

if( !rvecs.empty() && !tvecs.empty() )
{   
  CV_Assert(rvecs[0].type() == tvecs[0].type());
  Mat bigmat((int)rvecs.size(), 6, rvecs[0].type());

  for( int i = 0; i < (int)rvecs.size(); i++ )
  {
     Mat r = bigmat(Range(i, i+1), Range(0,3));
     Mat t = bigmat(Range(i, i+1), Range(3,6));

     CV_Assert(rvecs[i].rows == 3 && rvecs[i].cols == 1);
     CV_Assert(tvecs[i].rows == 3 && tvecs[i].cols == 1);
     //*.t() is MatExpr (not Mat) so we can use assignment operator
     r = rvecs[i].t();
     t = tvecs[i].t();
  }
  cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view",       0 );
  fs << "Extrinsic_Parameters" << bigmat;

My question is how the data is put into the 'bigmat'. To set values to the variable, 'bigmat' should be located in the right side but there isn't.

Is there somebody who is familiar with this kind of codes? Help me.

Thanks

1 Answers1

0

r and t matrices are in fact headers build for subset of bigmat data. So when You are putting something into r, You are in fact operating on bigmat. To prevent something like this to happen, You would need to use cv::MAt::clone(). Look up the documentation for mat, fourth bullet.

morynicz
  • 2,322
  • 2
  • 20
  • 34