匹配像素数据和点云

时间:2019-05-04 11:32:51

标签: point-cloud-library point-clouds

我必须组织从1D到2D的点云数据。 我已经有一个一维点云数据,该数据仅包含强度为255的像素(称为有效像素)的数据。 所以我必须根据图像组织点云。 我在访问2D点云时遇到问题。我不知道该怎么做。

// Here the data from in_ThreeD_cloud which is of type tDistanceData is converted to tVec3f
const rrlib::math::tVec3f *points = reinterpret_cast<const rrlib::math::tVec3f*>(in_ThreeD_cloud->DataPtr());

int num_valid_points = 0;

// An object to class PointCloud is created
pcl::PointCloud<pcl::PointXYZI> cloud; 

// Image data from the camera is accessed as Matrix
cv::Mat image  = rrlib::coviroa::AccessImageAsMat(in_img->at(0));

// Dimensions of the point cloud is sent as parameters to overloaded constuctor
cloud(image.cols, image.rows); 

// The point cloud is expected to store the vector3f data in a 2D format
for(int i = 0; i <= image.rows; ++i)
for(int j = 0; j <= image.cols; ++j)
{
     if( image.at<uchar>(i,j) == 255)
     {
       // Error shown here
       cloud.points[i][j].getVector3fMap() = &points[num_valid_points];
       num_valid_points++;

      }


}

显示的错误是: 错误:与“ operator []”不匹配(操作数类型为“ __gnu_cxx :: __ alloc_traits> :: value_type {aka pcl :: PointXYZI}”和“ int”)

1 个答案:

答案 0 :(得分:0)

完全确定问题出在您的点云访问呼叫中。您需要使用逗号表示法而不是第二个括号,并且我也相信(如果我错了,请纠正我),坐标必须按行,行顺序排列。 *代替您的[row] [col]订单。

我也将您的云更改为xyz,因为您没有在其中插入任何强度(而是只是检查图像以确定是否存在点)。

最后,请确保您知道点存储在3d云中的顺序(行与列),并确保以相同的方式遍历。

// An object to class PointCloud is created
pcl::PointCloud<pcl::PointXYZ> cloud; 

// Image data from the camera is accessed as Matrix
cv::Mat image  = rrlib::coviroa::AccessImageAsMat(in_img->at(0));

// Dimensions of the point cloud is sent as parameters to overloaded constuctor
cloud(image.cols, image.rows); 

// The point cloud is expected to store the vector3f data in a 2D format
for(int i = 0; i <= image.rows; ++i)
for(int j = 0; j <= image.cols; ++j)
{
     if( image.at<uchar>(i,j) == 255)
     {
       // Error shown here
       cloud.points[j,i].getVector3fMap() = &points[num_valid_points];
       num_valid_points++;

      }
}