Ask Your Question
0

OpenCV Error: Assertion failed (_dst.fixedType()) in cv::convertPointsHomogeneous

asked 2017-10-10 01:32:39 -0600

Ajay@velab gravatar image

updated 2020-10-23 07:11:19 -0600

Hello,

I am very new to Open CV, using Open CV 3.3.0 with visual studio 2012. While using cv::convertPointsHomogeneous(Thomogeneous, T) function , am getting error message like " Error: Assertion failed (_dst.fixedType()) in cv::convertPointsHomogeneous ", Could please any one help me !

Thanks in advance.

edit retag flag offensive close merge delete

Comments

we can't help without seing your code .. ;)

berak gravatar imageberak ( 2017-10-10 01:35:33 -0600 )edit

Hello Berak,

Thank you for the quick response, BTW am running project points example program provided in the below link. https://github.com/daviddoria/Example...

Kindly suggest me the possible solution, I am eagerly looking for that.

Thanks in Advance

Ajay@velab gravatar imageAjay@velab ( 2017-10-10 01:38:43 -0600 )edit

that's 5 year old, unmaintained opencv2.4 code ;(

berak gravatar imageberak ( 2017-10-10 01:58:12 -0600 )edit

Hello Berak,

Could u please suggest me any reference code block to understand pointprojection routine in Open CV.

Ajay@velab gravatar imageAjay@velab ( 2017-10-10 02:04:42 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-10-10 02:22:36 -0600

berak gravatar image

updated 2017-10-10 02:34:54 -0600

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,3); // 3 rows, 1 channel
edit flag offensive delete link more

Comments

1

Thank you So much, Sir, I will use this and appreciate your great help.

Ajay@velab gravatar imageAjay@velab ( 2017-10-10 02:27:22 -0600 )edit

Hello Berak Sir, Really it worked for me, but am again stuck in same Debug Assertion Failed error with the function cv::projectPoints(objectPoints, rvecR, T, K, distCoeffs, projectedPoints); This is sample code I am working on;

  cv::Mat K,rvec,Thomogeneous; 
  cv::decomposeProjectionMatrix(P, K, rvec, Thomogeneous);
  cv::Mat T;
  cv::convertPointsFromHomogeneous(Thomogeneous.reshape(4,1), T);  
  cv::Mat distCoeffs;
  distCoeffs.at<double>(0) = 0;
  distCoeffs.at<double>(1) = 0;
  distCoeffs.at<double>(2) = 0;
  distCoeffs.at<double>(3) = 0;
  std::vector<cv::Point2f> projectedPoints;
  cv::Mat rvecR(3,1,cv::DataType<double>::type);//rodrigues rotation matrix
  cv::Rodrigues(rvec,rvecR);
  cv::projectPoints(objectPoints, rvecR, T, K, distCoeffs, projectedPoints);
Ajay@velab gravatar imageAjay@velab ( 2017-10-10 08:53:17 -0600 )edit

According to your previous answer :

  // 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())

Do I need to reshape all the parameter of "cv::projectPoints()" to reshape ??

I tried with reshaping, but still getting the same error, Also a bit confused when it should be reshaped to single row ??

Thanks in Advance Sir.

Ajay@velab gravatar imageAjay@velab ( 2017-10-10 08:53:36 -0600 )edit

tbh, i did NOT play this through to the last line ;)

but yea, let me check again ..

berak gravatar imageberak ( 2017-10-10 09:19:01 -0600 )edit

Thank you, Sir, Will be waiting for your response

Ajay@velab gravatar imageAjay@velab ( 2017-10-11 00:04:20 -0600 )edit

you have to use: std::vector<cv::Point2d> projectedPoints; (double, not float.)

the type has to be consistent for all input/output and transformation Matrices.

berak gravatar imageberak ( 2017-10-11 01:04:37 -0600 )edit

Oh Yes, I missed that one.

Thank you lot for your continuous assistance, really it helped me lot Sir.

Ajay@velab gravatar imageAjay@velab ( 2017-10-11 01:11:20 -0600 )edit
berak gravatar imageberak ( 2017-10-11 01:14:17 -0600 )edit

Question Tools

Stats

Asked: 2017-10-10 01:32:39 -0600

Seen: 1,863 times

Last updated: Oct 10 '17