gpt4 book ai didi

memory-management - 似乎Random使使用Point Cloud Library处理Pointcloud崩溃-可能是内存问题?

转载 作者:行者123 更新时间:2023-12-03 16:00:49 27 4
gpt4 key购买 nike

我正在对点云进行几步重投影(最初大约为4000万个点,处理时约为2000万个点)。在这两个循环之一中,程序似乎在随机点处崩溃。如果我使用较小的子集(约1000万点)运行它,则一切正常。

//Projection of Point Cloud into a sphere 
pcl::PointCloud<pcl::PointXYZ>::Ptr projSphere(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,int radius)
{
//output cloud
pcl::PointCloud<pcl::PointXYZ>::Ptr output(new pcl::PointCloud<pcl::PointXYZ>);
//time marker
int startTime = time(NULL);
cout<<"Start Sphere Projection"<<endl;
//factor by which each Point Vector ist multiplied to get a distance of radius to the origin
float scalar;
for (int i=0;i<cloud->size();i++)
{
if (i%1000000==0) cout<<i<<endl;
//P
pcl::PointXYZ tmpin=cloud->points.at(i);
//P'
pcl::PointXYZ tmpout;
scalar=radius/(sqrt(pow(tmpin.x,2)+pow(tmpin.y,2)+pow(tmpin.z,2)));
tmpout.x=tmpin.x*scalar;
tmpout.y=tmpin.y*scalar;
tmpout.z=tmpin.z*scalar;
//Adding P' to the output cloud
output->push_back(tmpout);
}
cout<<"Finished projection of "<<output->size()<<" points in "<<time(NULL)-startTime<<" seconds"<<endl;
return(output);
}
//Stereographic Projection
pcl::PointCloud<pcl::PointXYZ>::Ptr projStereo(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
{
//output cloud
pcl::PointCloud<pcl::PointXYZ>::Ptr outputSt(new pcl::PointCloud<pcl::PointXYZ>);
//time marker
int startTime = time(NULL);
cout<<"Start Stereographic Projection"<<endl;
for (int i=0;i<cloud->size();i++)
{
//P
if (i%1000000==0) cout<<i<<endl;
pcl::PointXYZ tmpin=cloud->points.at(i);
//P'
pcl::PointXYZ tmpout;
//equation
tmpout.x=tmpin.x/(1.0+tmpin.z);
tmpout.y=tmpin.y/(1.0+tmpin.z);
tmpout.z=0;
//Adding P' to the output cloud
outputSt->push_back(tmpout);
}
cout<<"Finished projection of"<<outputSt->size()<<" points in "<<time(NULL)-startTime<<" seconds"<<endl;
return(outputSt);
}

如果我通过在硬盘上保存/加载点云并为每个步骤重新运行该程序来独立执行所有步骤,那么它也可以正常工作。我想提供整个源文件,但不确定如何/是否有必要。
提前致谢

编辑:1
大约一周后,我仍然不知道这里可能是什么问题,因为崩溃是随机的,但不是真的吗?我尝试用不同的系统工作负载(重新启动,加载了重型程序等)测试该程序没有明显的区别。由于我认为这可能是内存问题,因此我尝试将大型对象从堆栈移动到堆(使用new初始化),也没有任何区别。到目前为止,最大的对象是原始输入文件,我通过以下文件打开和关闭该文件:
    ifstream file;
file.open(infile);
/*......*/
file.close();
delete file;

这样做是否正确,以便在方法完成后释放内存?

再次编辑:
因此,我一步一步地尝试,最后我设法将所有步骤整合到一个函数中,如下所示:
void stereoTiffI(string infile, string outfile, int length)
{
//set up file input
cout<<"Opening file: "<< infile<<endl;
ifstream file;
file.open(infile);
string line;
//skip first lines
for (int i=0;i<9;i++)
{
getline(file,line);
}
//output cloud
pcl::PointCloud<pcl::PointXYZ> cloud;
getline(file,line);
//indexes for string parsing, coordinates and starting Timer
int i=0;
int j=0;
int k=0;
float x=0;
float y=0;
float z=0;
float intensity=0;
float scalar=0;
int startTime = time(NULL);
pcl::PointXYZ tmp;
//begin loop
cout<<"Begin reading and projecting"<< infile<<endl;
while (!file.eof())
{

getline(file,line);
i=0;
j=line.find(" ");
x=atof(line.substr(i,j).c_str());
i=line.find(" ",i)+1;
j=line.find(" ",i)-i;
y=atof(line.substr(i,j).c_str());
i=line.find(" ",i)+1;
j=line.find(" ",i)-i;
z=atof(line.substr(i,j).c_str());
//i=line.find(" ",i)+1;
//j=line.find(" ",i)-i;
//intensity=atof(line.substr(i,j).c_str());
//leave out points below scanner height
if (z>0)
{
//projection to a hemisphere with radius 1
scalar=1/(sqrt(pow(x,2)+pow(y,2)+pow(z,2)));
x=x*scalar;
y=y*scalar;
z=z*scalar;
//stereographic projection
x=x/(1.0+z);
y=y/(1.0+z);
z=0;
tmp.x=x;
tmp.y=y;
tmp.z=z;
//tmp.intensity=intensity;
cloud.push_back(tmp);
k++;
if (k%1000000==0)cout<<k<<endl;
}
}
cout<<"Finished producing projected cloud in: "<<time(NULL)-startTime<<" with "<<cloud.size()<<" points."<<endl;

实际上,这种方法可以很好,快速地退出。在下一步中,我尝试使用Pointtype XYZI,因为我还需要获取扫描点的强度。猜猜是什么,该程序再次崩溃在大约17000000,而我也不知道为什么。请帮忙

最佳答案

好的,我解决了。 Memory博士通过给我一个堆分配错误给了我正确的提示。经过一番谷歌搜索后,我在Visual Studio中启用了大地址(属性->链接器->系统)
一切都像魅力。

关于memory-management - 似乎Random使使用Point Cloud Library处理Pointcloud崩溃-可能是内存问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15357578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com