0

I have a sequence of images from which points of interest are extracted. to visualize the whole cloud point the pcl library is used. So two variables exist p which is the cloud of points extracted from one keyframe and the globalMap that is the concatenation of all the cloud points.

This is the code:

        generatePointCloud(pKF);
        pcl::PointCloud<pcl::PointXYZRGBA>::Ptr p(new pcl::PointCloud<pcl::PointXYZRGBA>);
        //Eigen::Matrix<double,4,4> Converter::toMatrix4d(const Sophus::SE3f &T)
        pcl::transformPointCloud(*(pKF->mptrPointCloud), *(p), Converter::toMatrix4d(pKF->GetPoseInverse()));
        {
            std::unique_lock<std::mutex> lck(mMutexGlobalMap);
            std::cout<<"MutexGlobalMap "<<std::endl;
            if (globalMap == nullptr) {
            std::cout<<"NUll pointer "<<std::endl;
            } else {
            std::cout<<"not empty "<<std::endl;
            }
            if (p == nullptr) {
            std::cout<<"NULL POINTER  "<<std::endl;
            } else {
            std::cout<<"not empty "<<std::endl;
            }
            if (p->size() > 0) {
            std::cout<<" P size "<<std::endl;
            cout<< p->size() <<endl;
            } else {
                cout<< p->size() <<endl;
            }
            if (globalMap->size() > 0) {
            std::cout<<" global map size "<<std::endl;
            cout<< globalMap->size() <<endl;

            } else {
                cout<< globalMap->size() <<endl;
            }

            // Check the type of globalMap Type of globalMap: N3pcl10PointCloudINS_12PointXYZRGBAEEE
            std::cout << "Type of globalMap: " << typeid(*globalMap).name() << std::endl;
            // Check the type of p Type of p: N3pcl10PointCloudINS_12PointXYZRGBAEEE
            std::cout << "Type of p: " << typeid(*p).name() << std::endl
            *globalMap += *p;

The debug messages give the following results:

Start processing sequence ...
Images in the sequence: 5178

First KF:0; Map init KF:0
New Map created with 575 points
receive a keyframe, 0
receive a keyframe, 1
receive a keyframe 
MutexGlobalMap 
not empty 
not empty 
 P size 
13415
0
Type of globalMap: N3pcl10PointCloudINS_12PointXYZRGBAEEE
Type of p: N3pcl10PointCloudINS_12PointXYZRGBAEEE
Added the point to the global map
tmp init
Setting Input Cloud
13415
receive a keyframe, 2
not empty 
not empty 
 P size 
13346
 global map size 
13415
Type of globalMap: N3pcl10PointCloudINS_12PointXYZRGBAEEE
Type of p: N3pcl10PointCloudINS_12PointXYZRGBAEEE
Segmentation fault (core dumped)

The segmentation fault occurs after the first addition to the global map. it occurs at this line *globalMap += *p; The debugger gives this message:

Thread 4 "rgbd_tum" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffd75b7700 (LWP 72283)]
__GI___libc_free (mem=0xb6934) at malloc.c:3102
3102    malloc.c: No such file or directory.

The expected result is a global map that contains all the cloud points from all the keyframes. Any idea how to fix this?

Botje
  • 26,269
  • 3
  • 31
  • 41
Iscelia
  • 1
  • 1
  • So, use your [debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) to step through the code line by line, inspect the call stack, local variable values etc. That's how you find out what's going on and what's wrong. Professional programmers don't guess, they test how their code executes, analyze and *think*. Once you know how to properly debug, asking questions like these become pointless. – Jesper Juhl May 03 '23 at 02:15
  • Included the debugger message. I am a total beginner that's why i am asking for help – Iscelia May 03 '23 at 02:30
  • 1
    The debugger cannot tell you a solution. It can just provide information. For example, it will stop at a segfault and you can then ask it to provide a stacktrace to see how you got into that mess or you can inspect local variables to see which ones may hold values you didn't expect etc, and much more. Please learn to use your debugger. – Jesper Juhl May 03 '23 at 02:35

0 Answers0