我正在研究"运动结构"。我想,当涉及到运动的结构时,人们会看到《多视图几何》这本书。这是一本非常好的书,但我在那本书中发现了一些令人困惑的数据。在下面的代码中,有一个名为Populate point cloud的函数,它有两个参数pointcloud和pointcloud_RGB。我在pointcloud中有point3d类型的值,但我在那本书中没有找到任何关于pointcloud_RGB的信息,它突然出现在这个函数中,这个函数用于填充VEC3d-rgbv。有人能帮助谁看到这本书吗。
void PopulatePCLPointCloud(const vector<cv::Point3d>& pointcloud,
const std::vector<cv::Vec3b>& pointcloud_RGB = std::vector<cv::Vec3b>()
)
{
cout<<"Creating point cloud...";
cloud.reset(new pcl::PointCloud<pcl::PointXYZRGB>);
for (unsigned int i=0; i<pointcloud.size(); i++) {
// get the RGB color value for the point
cv::Vec3b rgbv(255,255,255);
if (i < pointcloud_RGB.size()) {
rgbv = pointcloud_RGB[i];
}
// check for erroneous coordinates (NaN, Inf, etc.)
if (pointcloud[i].x != pointcloud[i].x ||
pointcloud[i].y != pointcloud[i].y ||
pointcloud[i].z != pointcloud[i].z ||
#ifndef WIN32
isnan(pointcloud[i].x) ||
isnan(pointcloud[i].y) ||
isnan(pointcloud[i].z) ||
#else
_isnan(pointcloud[i].x) ||
_isnan(pointcloud[i].y) ||
_isnan(pointcloud[i].z) ||
false
)
{
continue;
}
pcl::PointXYZRGB pclp;
pclp.x = pointcloud[i].x;
pclp.y = pointcloud[i].y;
pclp.z = pointcloud[i].z;
// RGB color, needs to be represented as an integer
uint32_t rgb = ((uint32_t)rgbv[2] << 16 | (uint32_t)rgbv[1] << 8 |
(uint32_t)rgbv[0]);
pclp.rgb = *reinterpret_cast<float*>(&rgb);
cloud->push_back(pclp);
}
cloud->width = (uint32_t) cloud->points.size(); // number of points
cloud->height = 1; // a list of points, one row of data
//Create visualizer
pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
viewer.showCloud (cloud);
cv::waitKey(0);
return;
}
我相信这是MasteringOpenCV第4章中的代码片段。我检查了整个项目,似乎这是中定义的某种错误pointcloud_RGB
const std::vector<cv::Vec3b>& pointcloud_RGB = std::vector<cv::Vec3b>()
并且除此之外不分配任何值;
rgbv = pointcloud_RGB[i];
这是在的条件下
if (i < pointcloud_RGB.size())
如果pointcloud_RGB为空,因此不能大于i,则程序永远不会进入此状态。这就是为什么它应该毫无问题地运行。
实点云是pcl::PointXYZRGB pclp;
,这里用XYZ坐标+RGB值填充;
pcl::PointXYZRGB pclp;
pclp.x = pointcloud[i].x;
pclp.y = pointcloud[i].y;
pclp.z = pointcloud[i].z;
// RGB color, needs to be represented as an integer
uint32_t rgb = ((uint32_t)rgbv[2] << 16 | (uint32_t)rgbv[1] << 8 |
(uint32_t)rgbv[0]);
当然,总有可能给作者发一封电子邮件,要求澄清。