Hi all,
I've been trying to work on solving this myself but failed short of new ideas. I am experiencing memory heap errors ever since I tried to transfer some functions (for calculating statistics i.e. getMode/getMean/getVariance) into a new class in the spirit of OOP.
Compiler error is...
--> This may be due to a corruption of the heap, and indicates a bug in try.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
This then takes me to the malloc.c file.
Note...
Whenever I execute the functions within the main() function all goes well, but whenever I transfer them to a separate header file and put up some class wrappings then call them from main() using a class variable, then the above error surfaces.
Weird enough, the error occurs not when I declare a stats (which is the name of the class enclosing the functions, but down the line where my Gabor function is called.
I've researched this on the internet but the answers are too specific for my case. I wanted to continue with the initial error-free approach but realized I cannot build up my C++ proficiency with such style. I'm pasting some of the code below, and have tried to highlight the problem areas (please ignore everything else). Please assist...
int main(int argc, char *argv[])
{
const int size = 256;
void saveMatrix(IplImage *g, dataStructure<uchar> *datastruct);
void populateMatrix(dataStructure<uchar> *data, IplImage *g, int &Ex);
int getMode(dataStructure<uchar> *data, int &Ef, int fx[]);
float getMean(int Efx, int Ef);
float getVariance(dataStructure<uchar> *data, int Ex, float mean);
void printMatrix(dataStructure<uchar> *data, haralickStructure *haralick);
void histogramEqualization(dataStructure<uchar> *data, int fx[]);
dataStructure<uchar> *data = new dataStructure<uchar>;
glcmStructure *glcm = new glcmStructure;
haralickStructure *haralik = new haralickStructure;
int max=0, min=0, mode=0, Ex=0, fx[size], Ef=0; float mean=0, stdev=0;
IplImage *a = cvLoadImage("c:\\tit\\lena.bmp"); // lena.bmp glcm.pgm baboon.tif syn.png
IplImage *g = cvCreateImage(cvGetSize(a),a->depth,1); // verts.JPG
cvCvtColor(a,g,CV_RGB2GRAY);
IplImage *b = cvCloneImage(g);
cvReleaseImage(&a);
populateMatrix(data, g, Ex);
/*haralick *m=new haralick(data);
m->calculateGLCM(0,1);
m->calculateHaralick();*/
------------------------------------------------------------------------------------
stats m(data); <--- this is where the problem is, but shows up
m.getStatistics(); <-- later in Gabor
-------------------------------------------------------------------------------------
mode = getMode(data, Ef, fx); // get mode
mean = getMean(Ex, Ef); // get Mean
stdev = (float) sqrt(getVariance(data,Ex,mean)); // standard deviation
//histogramEqualization(data,fx);
//saveMatrix(g, data);
//stats s(data);
//statistics<float> *r = s.getStatistics();
//Ex = r->Efx;
//mode = r->mode; mean=r->mean; stdev=r->stdev;
Console::WriteLine(L"\n Grey-Level Features ...");
Console::WriteLine(L"Sigma of x: \t\t" + Ex);
Console::WriteLine("Max Grey: \t\t" + data->maxGrey);
Console::WriteLine("Minimum Grey:\t\t" + data->minGrey);
Console::WriteLine("Mode: \t\t\t" + mode);
Console::WriteLine("Mean: \t\t\t" + mean);
Console::WriteLine(L"Standard deviation: \t" + stdev);
//printMatrix(data,haralik);
dataStructure<uchar> *had;
--------------------------------------------------------------------------------
Gabor ggb; <-- error shows up once this line executes
had = ggb.getGabor2D(data);
---------------------------------------------------------------------------------
//saveMatrix(g, data);
char *mn = "c:\\tit\\verts.JPG";
myImageClass dn(mn);
//dn.setFileName("c:\\tit\\save.JPG"); dn.saveMatrix();
//dn.setData(had);
IplImage *ig = dn.getImage();
//cvNamedWindow("dt2",1); cvShowImage("dt2",ig);
//cvWaitKey(0); cvDestroyAllWindows();
system("pause");
//cvReleaseImage(&g); g=0; ig=0;
data=0;
return 0;
}
Next is the class definition
#pragma once
#include "datastructs.h"
typedef unsigned char classDataType;
typedef float statDataType;
class stats
{
public:
stats(dataStructure<uchar> *datap);
statistics<float> * getStatistics();
// should be called in this order ... order is important
void getMode();
void getMean();
void getVariance();
statistics<statDataType> *statsData; // variable to hold calculated statistics
dataStructure<uchar> *d_data;
~stats(void);
};
I don't know what else you may need, please let me know. Thanks