Ask Your Question
0

How to convert vector<Point3f> to homogenous

asked 2016-11-19 10:31:19 -0600

Nbb gravatar image

updated 2016-11-19 11:41:56 -0600

I tried converting to Mat but it doesn't work. I don't know how to use vectors because there is not Point4f. This is the error I get if I use matrix input and output of converttohomogenous

OpenCV Error: Assertion failed (npoints >= 0) in cv::convertPointsToHomogeneous, file C:\Bin\opencv-master\source\modules\calib3d\src\fundam.cpp, line 965

vector<cv::Point3f> opencv_cloud(8);
//fill up
//Convert to homogenous mat
cv::Mat opencv_cloud_mat_homo, opencv_cloud_mat = cv::Mat(opencv_cloud).reshape(1).t();
cv::convertPointsToHomogeneous(opencv_cloud, opencv_cloud_mat_homo);

I have this but its manual and I dont know how to convert back to non homogenous i.e. divide the mat by the last row

//8 corners of aabb
vector<cv::Point3d> opencv_cloud(8), opencv_cloud_homo;
opencv_cloud[0] = cv::Point3d(-min.x, -min.y, min.z); opencv_cloud[1] = cv::Point3d(-min.x, -min.y, max.z);
opencv_cloud[2] = cv::Point3d(-max.x, -min.y, max.z); opencv_cloud[3] = cv::Point3d(-max.x, -min.y, min.z);
opencv_cloud[4] = cv::Point3d(-min.x, -max.y, min.z); opencv_cloud[5] = cv::Point3d(-min.x, -max.y, max.z);
opencv_cloud[6] = cv::Point3d(-max.x, -max.y, max.z); opencv_cloud[7] = cv::Point3d(-max.x, -max.y, min.z); 

//Convert to homogenous mat
cv::Mat opencv_cloud_mat_homo, opencv_cloud_mat = cv::Mat(opencv_cloud).reshape(1).t();
cv::vconcat(opencv_cloud_mat, cv::Mat::ones(cv::Size(8, 1), CV_64FC1), opencv_cloud_mat_homo);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-11-19 11:45:57 -0600

LBerger gravatar image

updated 2016-11-19 12:30:20 -0600

Something like this works

vector<Point3d> x={Point3d(1,2,3),Point3d(4,5,6),Point3d(7,8,9),Point3d(10,11,12),Point3d(13,14,15) };

Mat ww;
Mat wx(x);
cout << "vector<Point3> to matrix : " << wx.size() << endl <<wx<<endl;
convertPointsToHomogeneous(wx,ww);

cout << "matrix point to homogenous : " << ww.size() << endl << ww << endl;
ww.at<double>(1,3)=3;
cout << ww;
cout << " homogenous to matrix point3d : " << ww << endl;
convertPointsFromHomogeneous(ww,wx);
wx = wx.reshape(1, x.size());
cout << " homogenous to matrix point3d : " << wx.size() << endl << wx << endl;
edit flag offensive delete link more

Comments

aaaaaahhhh !!! so it becomes a matrix of 1 row 8 column and 4 channels and now I cant do matrix multiplications on it. Ill have to convert it to a matrix of 4 rows and 8 cols then matrix multiply then convert it to a matrix of 1 row and 8 column before i can use convertbackfromhomogenous, whoever thought the function should only behave this way is lame af

Nbb gravatar imageNbb ( 2016-11-19 12:02:47 -0600 )edit

use reshape

LBerger gravatar imageLBerger ( 2016-11-19 12:28:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-19 10:31:19 -0600

Seen: 2,973 times

Last updated: Nov 19 '16