将pcl点类型XYZ转换为Eigen Vector 4f

问题描述 投票:6回答:3

我试图将pcl pointXYZ转换为特征向量

Eigen::Vector4f min (minPnt.x, minPnt.y, minPnt.z);  
Eigen::Vector4f max (maxPnt.x, maxPnt.y, maxPnt.z);

其中minPnt和maxPnt的类型为pcl :: PointXYZ。但是,我收到错误“错误C2338:THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE”。你能否提出一些其他方法,或者让我知道我的方法是否错误。

c++ point-cloud-library eigenvector
3个回答
3
投票

请使用getVector4fMap()获取Eigen::Vector4f并使用getVector3fMap()获取Eigen::Vector3f

Eigen::Vector3f min = minPnt.getVector4fMap();
Eigen::Vector3f max = maxPnt.getVector4fMap();

如果您需要转换正常,请使用

pcl::Normal pcl_normal(0, 0, 1);
Eigen::Vector3f eigen_normal = pcl_normal.getNormalVector4fMap();

2
投票

我用下面的代码解决了上面的问题。

auto x_min = static_cast<float>(minPnt.x); 
auto y_min = static_cast<float>(minPnt.y); 
auto z_min = static_cast<float>(minPnt.z); 

auto x_max = static_cast<float>(maxPnt.x); 
auto y_max = static_cast<float>(maxPnt.y); 
auto z_max = static_cast<float>(maxPnt.z); 

Eigen::Vector4f min(x_min, y_min, z_min, 0.0); 
Eigen::Vector4f max(x_max, y_max, z_max, 0.0); 

如果有更好的方法,请建议。


1
投票

eigen :: vector4f正在寻找4个浮点数,但你只给它3个(x,y,z)。尝试在最后添加0:

Eigen :: Vector4f min(minPnt.x,minPnt.y,minPnt.z,0); 拥有:: Vector4f max(maxPnt.x,maxPnt.y,maxPnt.z,0);

© www.soinside.com 2019 - 2024. All rights reserved.