-1

I have 2 vectors (p1 and p2) of point3f variables which represent 2 3D pointclouds. In order to match these two point clouds I want to use SVD to find a transformation for this. The problem is that SVD requires a matrix (p1*p2 transpose). My question is how do I convert a vector of size Y to a Yx3 matrix?

I tried cv::Mat p1Matrix(p1) but this gives me a row vector with two dimensions.I also found fitLine but I think this only works for 2D.

Thank you in advance.

4

2 回答 2

0

怎么样:

cv::Mat p1copy(3, p1.size(), CV_32FC1);

for (size_t i = 0, end = p1.size(); i < end; ++i) {
    p1copy.at<float>(0, i) = p1[i].x;
    p1copy.at<float>(1, i) = p1[i].y;
    p1copy.at<float>(2, i) = p1[i].z;
}

如果这给了您想要的结果,您可以通过使用指针而不是相当慢的at<>()函数来使代码更快。

于 2014-07-28T08:44:06.520 回答
0

我使用 reshape 函数将点向量转换为 Mat。

vector<Point3f> P1,P2;
Point3f c1,c2;//center of two set
... //data association for two set
Mat A=Mat(P1).reshape(1).t();
Mat B=Mat(P2).reshape(1).t();

Mat AA,BB,CA,CB;
repeat(Mat(c1),1,P1.size(),CA);
repeat(Mat(c2),1,P2.size(),CB);
AA=A-CA;
BB=B-CB;
Mat H=AA*BB.t();
SVD svd(H);
Mat R_;
transpose(svd.u*svd.vt,R_);
if(determinant(R_)<0)
    R_.at<float>(0,2)*=-1,R_.at<float>(1,2)*=-1,R_.at<float>(2,2)*=-1;
Mat t=Mat(c2)-R_*Mat(c1);
于 2015-08-09T14:47:58.953 回答