我们在图像处理项目中使用Blodshed Dev-C ++。我们正在视频帧上实现连接的组件标签。我们必须使用一个递归函数,该函数递归多次,以至于出现堆栈溢出。我们如何拥有更大的堆栈大小?是否可以通过某些链接器参数或类似的参数进行更改?
void componentLabel(int i,int j,IplImage *img){
// blueFrame = img->imageData[i*3*width+j*3];
// greenFrame = img->imageData[i*3*width+j*3+1];
// redFrame = img->imageData[i*3*width+j*3+2];
if(!( img->imageData[i*3*width+j*3]==0 && img->imageData[i*3*width+j*3+1]==0 && img->imageData[i*3*width+j*3+2]==0 ) ){
//printf("iffffff aq\n");
return;
}
else{
//printf("else aq %d\n",sayac_label);
img->imageData[i*3*width+j*3]=1;
new_object.pixel_count=new_object.pixel_count+1;
new_object.total_row=new_object.total_row+i;
new_object.total_col=new_object.total_col+j;
if(j<width-1 ){
componentLabel(i,j+1,img);
}
if(j>0 ){
componentLabel(i,j-1,img);
}
if(i<height-1 ){
if(i>new_object.bottom.satir){
new_object.bottom.satir=i;
new_object.bottom.sutun=j;
}
componentLabel(i+1,j,img);
}
if(i>0 ){
if(i<new_object.top.satir){
new_object.top.satir=i;
new_object.top.sutun=j;
}
return componentLabel(i-1,j,img);
}
}
最佳答案
只有一种方法可以确保您不会耗尽堆栈大小-将算法重新设计为尾部递归(并确保编译器正在优化尾部调用-通常为-O3(或-O2?)优化标志)。
除此之外,您是否增加了Shell授予任务的最大堆栈大小?
ulimit -s <maximum stack size>
关于c - 如何在Bloodshed Dev-C++中增加堆栈大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10018207/