背景
我正在制作立体相机& amp;我试图找到两点云的Homography Matrix。当我试图在3D中找到单应性时,它主要失败了。这花费了太多时间。所以我想通过在2D&中找到Homography来加速这个过程。然后使用ICP算法拟合目标点云。
问题
如何将Homography Matrix从2D图像映射到3D Point云?我见过this answer&试图改变点云,但它失败了。有人可以指导我,如何在3D中使用2D单应矩阵?如果你分享一些文件会非常有用!
注意:
样本数据
1)LeftImage,LeftPointCloud 2)RightImage,RightPointCloud
这是我的简短code。
UMat mSource_Img, mTarget_Img;
string leftImageName = "PointCloudFrame_0.bmp";
string rightImageName = "PointCloudFrame_1.bmp";
string leftPCloudName = "PointCloudFrame_0.pcd";
string rightPCloudName = "PointCloudFrame_1.pcd";
imread(leftImageName, IMREAD_GRAYSCALE).copyTo(mSource_Img);
if(mSource_Img.empty())
{
cout << "Couldn't load " << leftImageName << endl;
return EXIT_FAILURE;
}
imread(rightImageName, IMREAD_GRAYSCALE).copyTo(mTarget_Img);
if(mTarget_Img.empty())
{
cout << "Couldn't load " << rightImageName << endl;
return EXIT_FAILURE;
}
Timer t_H;
t_H.start();
SURFFeatureDetector FD_surf;
Mat H_2D;
FD_surf.FindHomographyMatrix(mSource_Img,mTarget_Img,H_2D,0,1);
Mat mTransformed_Img;
warpPerspective(mSource_Img, mTransformed_Img, H_2D, mTarget_Img.size());
t_H.stop();
cout<<"Time taken for Homography Estimation: "<<t_H.getElapsedTimeInMilliSec();
imshow("mSource_Img", mSource_Img);
imshow("mTarget_Img", mTarget_Img);
addWeighted(mTarget_Img,0.5,mTransformed_Img,0.5,1.0,mTransformed_Img);
imshow("source_Transformed", mTransformed_Img);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_pcd (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_transformed_pcd (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr target_pcd (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile (leftPCloudName, *source_pcd);
pcl::io::loadPCDFile (rightPCloudName, *target_pcd);
cout<<"\nHomography 2D:\n"<<H_2D<<"\n";
pcl::visualization::CloudViewer PclViewer("Stereo Point Cloud Viewer");
Eigen::Matrix4f RotationMat3D=Eigen::Matrix4f::Identity();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
RotationMat3D(i,j)=(float)H_2D.at<double>(i,j);
}
}
cout<<"\Rotation 3D:\n"<<RotationMat3D<<"\n";
//RotationMat3D*=RotationMat2D;
pcl::transformPointCloud (*source_pcd, *source_transformed_pcd, RotationMat3D);
if(!PclViewer.wasStopped())
PclViewer.showCloud(source_transformed_pcd);
waitKey(0);