dso_with_saving_pcl icon indicating copy to clipboard operation
dso_with_saving_pcl copied to clipboard

How to display the pcd file?

Open phenix1983 opened this issue 6 years ago • 2 comments

I' m sorry, I have run the code,and generate pcd file, and use the following code get valid PCD file, the point cloud map is not as clear as displayed in the ProjectDSO. #include //标准C++库中的输入输出的头文件 #include #include #include <unistd.h> #include <pcl/io/pcd_io.h> //PCD读写类相关的头文件 #include <pcl/point_types.h> //PCL中支持的点类型的头文件 #include <stdio.h> #include <stdlib.h> #include <string.h>

int main (int argc, char** argv) { //read input file std::ifstream ifs;//ifstream ifs(argv[1]); ifs.open("cloudPoint_output.txt"); std::string temp; char bufftemp[255]; char* pcWorld_x; char* pcWorld_y; char* pcWorld_z; double pfWorld_x; double pfWorld_y; double pfWorld_z; char* pcDelimeter = " "; char* pcSave = NULL;

//PCL

pcl::PointCloud<pcl::PointXYZ> cloud;

// 创建点云  并设置适当的参数(width height is_dense)
cloud.width    = 450145;
cloud.height   = 1;
cloud.is_dense = false;  //不是稠密型的
cloud.points.resize (cloud.width * cloud.height);  //点云总数大小

int i = 0;
//if(ifs.is_open())
{
    while(!ifs.eof())
    {
        getline(ifs,temp);
        strcpy(bufftemp,temp.c_str());
        pcWorld_x = strtok(bufftemp,pcDelimeter);
        pcWorld_y = strtok(NULL,pcDelimeter);
        pcWorld_z = strtok(NULL,pcDelimeter);
        pfWorld_x = atof(pcWorld_x);
        pfWorld_y = atof(pcWorld_y);
        pfWorld_z = atof(pcWorld_z);
        /*pcWorld_x = strtok_r(bufftemp,pcDelimeter,&pcSave);
        pcWorld_y = strtok_r(NULL,pcDelimeter,&pcSave);
        pcWorld_z = strtok_r(NULL,pcDelimeter,&pcSave);
        pfWorld_x = atof(pcWorld_x);
        pfWorld_y = atof(pcWorld_y);
        pfWorld_z = atof(pcWorld_z);*/

        //for (size_t i = 0; i < cloud.points.size (); ++i)
        {

            std::cout <<"i=" << i<< " x=" << pfWorld_x <<" y="<< pfWorld_y << " z=" << pfWorld_z << std::endl;
            cloud.points[i].x = pfWorld_x;
            cloud.points[i].y = pfWorld_y;
            cloud.points[i].z = pfWorld_z;
        }
        if(i == (cloud.points.size ()-1))
        {
            break;
        }
        i++;
        
    }
}
pcl::io::savePCDFileASCII ("test_pcd_2.pcd", cloud);
return 0;

}

phenix1983 avatar Apr 25 '18 08:04 phenix1983

@phenix1983 Hi, you can view point cloud which you saved by PCD file using simple point cloud viewer.

refer to this link : http://pointclouds.org/documentation/tutorials/cloud_viewer.php

Neoplanetz avatar Apr 26 '18 05:04 Neoplanetz

@Neoplanetz Thanks for sharing your codes. I wonder besides the dso/src/IOWrapper/OutputWrapper/SampleOutputWrapper.h file, is there other file did you modify to make the pcl importation function work? Thank you.

jwangjie avatar Jan 17 '19 00:01 jwangjie