使用OpenGL执行Point Cloud但不断发生堆栈溢出

时间:2014-06-30 07:35:38

标签: opengl stack-overflow point-clouds

我正在努力做点云但是 堆栈总是溢出,请帮忙! 我哪里做错了? (g_bmp.h包含输入图像)

或者我应该如何使用OpenGL从输入图像中制作点云?

#include <stdio.h>

#include "glut.h"
#include "g_bmp.h"

float ORG[3] = {0,0,0};

float XP[3] = {1,0,0}, YP[3] = {0,1,0}, ZP[3] = {0,0,1};

void display()
{
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluPerspective( 20, 1, 0.1, 10 );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt( 
     1,1,2,
     0 ,0 ,0,
     0,1,0 );

    glLineWidth (10.0);
    glBegin(GL_LINES);
        glColor3f (1,0,0); // X axis is red.
        glVertex3fv (ORG);
        glVertex3fv (XP ); 
        glColor3f (0,1,0); // Y axis is green.
        glVertex3fv (ORG);
        glVertex3fv (YP );
        glColor3f (0,0,1); // z axis is blue.
        glVertex3fv (ORG);
        glVertex3fv (ZP ); 
    glEnd();

    GBmp bm0;                   //the input image     
    bm0.load( "image.bmp" );    //the input image

    float imgdata[320][240][3]; //contains the three-dimensional coordinates
    float texture[320][240][3]; //contains the color values for each point
    float x, y, z;
    glPointSize (1);
    glBegin(GL_POINTS);
        for (int i=0; i<320; i++)
        {
            for (int j=0; j<240; j++)
            {
                glColor3f(texture[i][j][0]/255, texture[i][j][1]/255,                texture[i][j][2]/255);
                x=imgdata[i][j][0];
                y=imgdata[i][j][1];   
                z=imgdata[i][j][2];   
                glVertex3f(x,y,z);   
            }
        }   
    glEnd();
    glFlush();  
glutSwapBuffers();
}

void main()
{
  glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
  glutInitWindowSize( 320, 240 );
  glutCreateWindow( "3D" );
  glutDisplayFunc(display);
  glutMainLoop();
}

1 个答案:

答案 0 :(得分:0)

这些行可能是你的问题:

float imgdata[320][240][3]; //contains the three-dimensional coordinates
float texture[320][240][3]; //contains the color values for each point

这是在堆栈上分配的2*320*240*3*sizeof(float)=1 843 200个字节或1.8 MB堆栈从来没有意味着保持那么多

快速修复,您可以在堆上分配它们或使它们成为全局变量,以便更全面地修复非固定功能管道的端口和缓冲区来保存它们