1
votes

I have an organized point cloud (1280 * 720) captured from a 3D camera. I just wonder whether there's a method to resize(cut down) this point cloud to a smaller size (eg. 128 * 72), when keeping this cloud organized. (I think this shouldn't be the same as down sampling. "Resize" means like zooming an image).

I am using Point Cloud Library 1.8.0 but stuck with this.

Any advice is welcome, thanks first!

3

3 Answers

2
votes

The answer of Rooscannon is in particular correct, but has some bugs in it. The correct uniform subsampling of a organized point cloud is as follows:

// Downsampling or keypoint extraction
int scale = 3;
PointCloud<PointXYZRGB>::Ptr keypoints (new PointCloud<PointXYZRGB>);
keypoints->width = cloud->width / scale;
keypoints->height = cloud->height / scale;
keypoints->points.resize(keypoints->width * keypoints->height);
for( size_t i = 0, ii = 0; i < keypoints->height; ii += scale, i++){
    for( size_t j = 0, jj = 0; j < keypoints->width; jj += scale, j++){
      keypoints->at(j, i) = cloud->at(jj, ii); //at(column, row)
    }
}

So the loop conditions, the indexing and the initialization of the subsampled point cloud are different. Otherwise, the subsampled point cloud would not be organized anymore.

1
votes

Just take a point out of the number of time you want to reduce your cloud, something like that shloud work :

for (pcl::PointCloud<pcl::PointXYZ>::const_iterator it = src->begin(); it< src->end(); it+=times)
{
  dest.points.push_back(*it);
}

Only problem is the cloud might containt some NaN values. To correct it just set is_dense to false into dest and call removeNaNFromPointCloud on it.

Hope this can help you !

0
votes

Can't comment but removing NaNs from your point cloud by default makes it unorganized. Quite likely the NaNs are there as dummy points in case your instrument was not able to observe a point in the matrix just to keep the matrix dimensions correct. Removing those breaks the matrix structure and you'll have a different amount of points than your 1280 * 720 matrix would expect.

If you wish to down sample an organized point cloud say by a factor of 2, you could try something like

int scale = 2;
pcl::PointCloud<pcl::your_point_type> down_sampled_cloud; 
down_sampled_cloud.width = original_cloud.width / scale;
down_sampled_cloud.height = original_cloud.height / scale;

for( int ii = 0; ii < original_cloud.height; ii+=scale){
    for( int jj = 0; jj < original_cloud.width; jj+=scale ){
    down_sampled_cloud.push_back(original_cloud.at(ii,jj));

    }
}

Change scale to what you wish.

This method just down samples the original point cloud, it will not interpolate points between existing points. Scaling by a decimal factor is trickier and might yield unwanted results if the surface is not continuous.