PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.86k stars 4.61k forks source link

icp setIndices doesn't work #3109

Open yzl96 opened 5 years ago

yzl96 commented 5 years ago

I first generate 1000 random points to form the source point cloud: for (size_t i = 0; i < cloud_in->points.size (); ++i) { cloud_in->points[i].x = 1024 rand () / (RAND_MAX + 1.0f); cloud_in->points[i].y = 1024 rand () / (RAND_MAX + 1.0f); cloud_in->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } and then form the target point cloud from the front 100 points of source point cloud , and add 0.7 to x for (size_t i = 0; i < cloud_out->points.size (); ++i) { cloud_out->points[i].x = cloud_in->points[i].x + 0.7f; cloud_out->points[i].y = cloud_in->points[i].y; cloud_out->points[i].z = cloud_in->points[i].z; } I try two times for the indices: boost::shared_ptr< std::vector > pr(new std::vector); // first try // for(int i=0; i<100; i+=1) // pr->push_back(i); // second try for(int i=100; i<200; i+=1) pr->push_back(i); but the result transformation is the same, if the setIndices works, the result shouldn't be the same, because the points in source point cloud we use to registration is different.

Your Environment

Context

Expected Behavior

Current Behavior

Code to Reproduce

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out (new pcl::PointCloud<pcl::PointXYZ>);

    // Fill in the CloudIn data
    cloud_in->width    = 1000;
    cloud_in->height   = 1;
    cloud_in->is_dense = false;
    cloud_in->points.resize (cloud_in->width * cloud_in->height);
    for (size_t i = 0; i < cloud_in->points.size (); ++i)
    {
        cloud_in->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
        cloud_in->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
        cloud_in->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
    }

    cloud_out->width    = 100;
    cloud_out->height   = 1;
    cloud_out->is_dense = false;
    cloud_out->points.resize (cloud_out->width * cloud_out->height);

    for (size_t i = 0; i < cloud_out->points.size (); ++i)
    {
        cloud_out->points[i].x = cloud_in->points[i].x + 0.7f;
        cloud_out->points[i].y = cloud_in->points[i].y;
        cloud_out->points[i].z = cloud_in->points[i].z;
    }
    std::cout << cloud_out->points.size() << std::endl;

    boost::shared_ptr< std::vector<int> > pr(new std::vector<int>);
   // first try
   //   for(int i=0; i<100; i+=1)
    //    pr->push_back(i);
 // second try
    for(int i=100; i<200; i+=1)
        pr->push_back(i);

    pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
    icp.setMaxCorrespondenceDistance(0.5);
    icp.setTransformationEpsilon(1e-12);
    icp.setEuclideanFitnessEpsilon(0.0001);
    icp.setMaximumIterations (1000000);
    icp.setInputSource(cloud_in);
    icp.setInputTarget(cloud_out);

    //icp.setIndices(pr);
    pcl::PointCloud<pcl::PointXYZ> Final;
    icp.align(Final);

    std::cout << "has converged:" << icp.hasConverged() << " score: " <<
              icp.getFitnessScore() << std::endl;

    std::cout << icp.getFinalTransformation() << std::endl;

    pcl::transformPointCloud(*cloud_out,*cloud_out,icp.getFinalTransformation().inverse());

Possible Solution

taketwo commented 5 years ago

Yes, you use different points in the input cloud, but the transform is nevertheless the same, 0.7 along the x axis. Why would it be different?

yzl96 commented 5 years ago

@taketwo , I did use different points in the input cloud, but my output point cloud is fixed, my output cloud have 100 points, which are generated by add 0.7 to x axis from first 100 points of the input point cloud, if I set indices [0,99] of input point cloud, there is a transformation 0.7 in x axis between input cloud subset and output cloud, but if I set indices [100,199], there should no relation between input cloud subset and output cloud, my output point cloud is generate from the first 100 points of input cloud, it has no relation with the input cloud subset (indices from 100 to 199).

yzl96 commented 5 years ago

@taketwo , how can it be same, the setIndices function choose the subset of input point cloud to register with output cloud, I use different subset of input cloud, and output point cloud is fixed, why the transfomation is the same, the input of registration is different.

taketwo commented 5 years ago

Hi, actually you may be right about this one. I had a brief look at the ICP code and it does not seem to pay attention to supplied indices indeed.

stale[bot] commented 4 years ago

Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.