c++ - Insufficent Memory -


i new open cv , have been working on project on gesture recognition. implementing pca , while calculating eigen vectors. stumbled upon insufficient memory error. 2d arrays used dynamically allocated. still same error creeps up. here code:

    void initialization()     {       long int nrows=15000, ncolumns=20;   int i,j;        cov = (float**) malloc(nrows * sizeof(float *));             for(i = 0; < nrows; i++)       {                    cov[i] = (float*) malloc(ncolumns * sizeof(float));                     }             matrix = (int**) malloc(15000 * sizeof(int *));      for(i = 0; < nrows; i++)       {                    matrix[i] = (int*) malloc(20 * sizeof(int));                     }            matrix1 = (int**) malloc(15000* sizeof(int *));      for(i = 0; < nrows; i++)       {                    matrix1[i] = (int*) malloc(20 * sizeof(int));                     }         .....                     }      void cal_eigen()     {        //mat original matrix     cout<<"mat conversion"<<endl;      (i = 0; < 10; i++)     {   (j = 0; j < 12300; j++)   {     matrix1_clone[i][j]=matrix1[j][i];   }     }      cvinitmatheader( mat, 12300, 10, cv_64fc1, matrix);     cvinitmatheader( matt, 12300, 10, cv_64fc1,matrix1);      cvinitmatheader( matty, 10, 12300, cv_64fc1, mat_inv);          cvinitmatheader( covar, 12300, 12300, cv_64fc1, cov);        int i,j;     int temp1 = 0;              int arry[mat->cols];           int arry1[matt->cols];           int arry2[matty->cols];            int * temp_array=  ( int *) malloc ( (mat->rows * mat->cols) * sizeof(int));             int *temp1_array= (int*) malloc ((matt->rows * matt->cols) * sizeof(int));              int counter=-1;             for(j=0; j<mat->cols; j++)            {             arry[j] = matrix[0][j];// 0-9 values stored.             arry1[j] = matrix1[0][j];             }          for( i=1; i<mat->rows;i++)       {          ( j=0;j<mat->cols;j++)           {                   counter ++;              temp_array[counter]= matrix[i][j];               temp1_array[counter]=matrix1[i][j];             }              }      int k=0;        for(i=0;i<mat->rows;i++)      {            ( j=0;j<mat->cols;j++)            {           if(i == 0)     {             cvsetreal2d(mat,i,j,(double) arry[j]);             cvsetreal2d(matt,i,j,(double) arry1[j]);           }      else{           cvsetreal2d(mat,i,j,(double)temp_array[k]);          cvsetreal2d(matt,i,j,(double)temp1_array[k]);             k++;            }                 }          }          for(i=0;i<10;i++)          { cout<<"ere";             ( j=0;j<12300;j++)               {               cvsetreal2d(matty,i,j,(double) matrix1_clone[i][j]);                }           }            cvreleasemat(&matt);                cvmatmul(mat,matty,covar);                 for(i=0;i<12300;i++)           {             for(j=0;j<12300;j++)          {           temp = cvmget(covar,i,j);          temp = (temp/12300);          cvmset(covar,i,j,temp);           }          }                cvreleasemat(&mat);          cvreleasemat(&matty);             //error pops here          cvmat* evec  = cvcreatemat(1,10,cv_64fc1); //eigenvectors         cvmat* eval  = cvcreatemat(1,10,cv_64fc1);  //eigenvalues (1xn)         cvzero(evec);         cvzero(eval);         cveigenvv( covar, evec, eval,dbl_epsilon,0,0);         cvreleasemat(&covar); 

the error opencv error:

insufficient memory (failed allocate 1210320004 bytes) in outofmemoryerror, file /home/ukri/src/opencv-2.4.2/modules/core/src/alloc.cpp, line 52 terminate called after throwing instance of 'cv::exception'   what():  /home/ukri/src/opencv-2.4.2/modules/core/src/alloc.cpp:52: error: (-4) failed allocate 1210320004 bytes in function outofmemoryerror 

i appreciate if guys me out problem.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -