Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

well, those functions in calib3d are a bit inconsistent, whether to use N channels or N rows to store the data, if you work longer with that, i''ll promise you more "fun" like that xD. (and obviously, trying with 5 year old code does not really help..)

let's shorten the problem:

  cv::Mat P(3,4,cv::DataType<double>::type);
  // Decompose the projection matrix into:
  cv::Mat K,rvec,Thomogeneous; /// but let opencv decide the type/shape !

  cv::decomposeProjectionMatrix(P, K, rvec, Thomogeneous);

  //
  // now, Thomogeneous  is a Mat(4,1,CV_64F), 
  //    but the next function requires Mat(1,1,CV_64FC4) ;
  //   so we're going to reshape it, simply.
  //   also, let's be more explicit, about which direction this is going (4->3)
  //
  cv::Mat T;
  cv::convertPointsFromHomogeneous(Thomogeneous.reshape(4,1), T);

well, those functions in calib3d are a bit inconsistent, whether to use N channels or N rows to store the data, if you work longer with that, i''ll promise you more "fun" like that xD. (and obviously, trying with 5 year old code does not really help..)

let's shorten the problem:

  cv::Mat P(3,4,cv::DataType<double>::type);
  // Decompose the projection matrix into:
  cv::Mat K,rvec,Thomogeneous; /// but let opencv decide the type/shape !

  cv::decomposeProjectionMatrix(P, K, rvec, Thomogeneous);

  //
  // now, Thomogeneous  is a Mat(4,1,CV_64F), 
  //    but the next function requires Mat(1,1,CV_64FC4) ;
  //   so we're going to reshape it, simply.
  //   also, let's be more explicit, about which direction this is going (4->3)
  //     (and use ...FromHomogeneous())
  //
  cv::Mat T;
  cv::convertPointsFromHomogeneous(Thomogeneous.reshape(4,1), T);

well, those functions in calib3d are a bit inconsistent, whether to use N channels or N rows to store the data, if you work longer with that, i''ll promise you more "fun" like that xD. (and obviously, trying with 5 year old code does not really help..)

let's shorten the problem:

  cv::Mat P(3,4,cv::DataType<double>::type);
  // Decompose the projection matrix into:
  cv::Mat K,rvec,Thomogeneous; /// but let opencv decide the type/shape !

  cv::decomposeProjectionMatrix(P, K, rvec, Thomogeneous);

  //
  // now, Thomogeneous  is a Mat(4,1,CV_64F), 
  //    but the next function requires Mat(1,1,CV_64FC4) ;
  //   so we're going to reshape it, simply.
to 4 channels, and a single row.
  //   also, let's be more explicit, about which direction this is going (4->3)
  //     (and use ...FromHomogeneous())
  //
  cv::Mat T;
  cv::convertPointsFromHomogeneous(Thomogeneous.reshape(4,1), T);

well, those functions in calib3d are a bit inconsistent, whether to use N channels or N rows to store the data, if you work longer with that, i''ll promise you more "fun" like that xD. (and obviously, trying with 5 year old code does not really help..)

let's shorten the problem:

  cv::Mat P(3,4,cv::DataType<double>::type);
  // Decompose the projection matrix into:
  cv::Mat K,rvec,Thomogeneous; /// but let opencv decide the type/shape !

  cv::decomposeProjectionMatrix(P, K, rvec, Thomogeneous);

  //
  // now, Thomogeneous  is a Mat(4,1,CV_64F), 
  //    but the next function requires Mat(1,1,CV_64FC4) ;
  //   so we're going to reshape it, to 4 channels, and a single row.
  //   also, let's be more explicit, about which direction this is going (4->3)
  //     (and use ...FromHomogeneous())
  //
  cv::Mat T;
  cv::convertPointsFromHomogeneous(Thomogeneous.reshape(4,1), T);

  // T will be Mat(1,1,CV_64FC3), now. 
  // if you need it as Mat(3,1,CV64F) later on (and you probably will !),
  //   do the reverse reshape:
  // T = T.reshape(1,1);

well, those functions in calib3d are a bit inconsistent, whether to use N channels or N rows to store the data, if you work longer with that, i''ll promise you more "fun" like that xD. (and obviously, trying with 5 year old code does not really help..)

let's shorten the problem:

  cv::Mat P(3,4,cv::DataType<double>::type);
  // Decompose the projection matrix into:
  cv::Mat K,rvec,Thomogeneous; /// but let opencv decide the type/shape !

  cv::decomposeProjectionMatrix(P, K, rvec, Thomogeneous);

  //
  // now, Thomogeneous  is a Mat(4,1,CV_64F), 
  //    but the next function requires Mat(1,1,CV_64FC4) ;
  //   so we're going to reshape it, to 4 channels, and a single row.
  //   also, let's be more explicit, about which direction this is going (4->3)
  //     (and use ...FromHomogeneous())
  //
  cv::Mat T;
  cv::convertPointsFromHomogeneous(Thomogeneous.reshape(4,1), T);

  // T will be Mat(1,1,CV_64FC3), now. 
  // if you need it as Mat(3,1,CV64F) later on (and you probably will !),
  //   do the reverse reshape:
  // T = T.reshape(1,1);
T.reshape(1,3); // 3 rows, 1 channel