From 0918e48d8ce67ee85b84918bd621c66aba2c7060 Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Thu, 27 Sep 2012 19:13:04 -0400 Subject: fixed a memory leak, now calculate inline so there is no huge overhead --- fly-tools/background/main.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'fly-tools/background') diff --git a/fly-tools/background/main.cpp b/fly-tools/background/main.cpp index 2c9fd60..a8d0167 100644 --- a/fly-tools/background/main.cpp +++ b/fly-tools/background/main.cpp @@ -12,7 +12,7 @@ int nImages; unsigned long height = 0; unsigned long width = 0; -int findmax (uint8_t *p, int n) { +int findmax(long *p, int n) { int mx = 0, v = p[0]; for (int i = 1; i < n; i++) { if (p[i] > v) { @@ -54,7 +54,8 @@ int main(int argc, char **argv ) { exit(EXIT_FAILURE); } - IplImage *first_image, *input_image, *output_image; + IplImage *first_image = NULL; + IplImage *output_image = NULL; int i,j, k; int image = 0; @@ -62,7 +63,6 @@ int main(int argc, char **argv ) { string filename; - // open first image in input_file to deterimine the height and width ifstream input_file(inputFileName.c_str()); @@ -104,7 +104,7 @@ int main(int argc, char **argv ) { cout << "number of images: " << nImages << endl; // initialize the storage arrays - uint8_t * array = (uint8_t *)malloc(nImages*height*width*3*sizeof(uint8_t)); + long * array = (long *)malloc(height*width*256*3*sizeof(long)); if(array == NULL) { cerr << "could not allocate the proper memory, sorry!" << endl; exit(EXIT_FAILURE); @@ -115,22 +115,27 @@ int main(int argc, char **argv ) { while (input_file>>filename) { + IplImage *input_image = NULL; input_image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_UNCHANGED); cout << "Image number " << image << "Filename " << filename << endl; for (j=0; j