gaoxiang12 / ORBSLAM2_with_pointcloud_map

830 stars 346 forks source link

How can I save the pointcloud_map? #42

Closed Taeyoung96 closed 2 years ago

Taeyoung96 commented 3 years ago

Hi, I'm really thankful for your great code!
I execute the code and get a Great Result :smile:

In my case, I want to save the Point cloud map, so I want to fix some code.

By the way, Where can I fix it, and How to save the point cloud map?

If someone does this work, could you give me some tips?

Thanks.

Landerku commented 2 years ago

Hi, I think it works like this: `void PointCloudMapping::viewer() { pcl::visualization::CloudViewer viewer("viewer"); while(1) { { unique_lock lck_shutdown( shutDownMutex ); if (shutDownFlag) { break; } } { unique_lock lck_keyframeUpdated( keyFrameUpdateMutex ); keyFrameUpdated.wait( lck_keyframeUpdated ); }

    // keyframe is updated 
    size_t N=0;
    {
        unique_lock<mutex> lck( keyframeMutex );
        N = keyframes.size();
    }

    for ( size_t i=lastKeyframeSize; i<N ; i++ )
    {
        PointCloud::Ptr p = generatePointCloud( keyframes[i], colorImgs[i], depthImgs[i] );
        //PointCloud::Ptr p = generatePointCloud( keyframes[i], colorImgs[i], depthImgs[i] );
        if(!p)
        {
            continue;
        }else{

            *globalMap += *p;
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr p1 (new pcl::PointCloud<pcl::PointXYZRGBA> ());
            pcl::copyPointCloud(*p, *p1);
            *globalMap1 += *p1;

            /*globalMap += *p;
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr p1 (new pcl::PointCloud<pcl::PointXYZRGBA> ());
            pcl::copyPointCloud(*p, *p1);
            *globalMap1 += *p1;*/
        }

    }
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr tmp (new pcl::PointCloud<pcl::PointXYZRGBA> ());
    //PointCloud::Ptr tmp(new PointCloud());
    voxel.setInputCloud( globalMap1 );
    voxel.filter( *tmp );
    globalMap1->swap( *tmp );
    viewer.showCloud( globalMap1 );
    cout<<"show global map, size="<<globalMap1->points.size()<<endl;
    lastKeyframeSize = N;
}

}`

Above is the original file in this repository and I added some changes, you can see the corresponding varaiable with the following function:

void PointCloudMapping::Save() { //pcl::io::savePCDFile("RGB.pcd", globalMap); pcl::io::savePCDFile("Segmentation.pcd", globalMap1); cout << "Map save finished!" <<endl; }

Taeyoung96 commented 2 years ago

@Landerku Thank you for your answer.
I modified some codes by referring to your answer. 😄