#include #include #include #include #include #include #define round(x)((int)((x)+0.5)) #define array(i,j,k,l) (array[height*width*i + width*j + k + l]) int nImages; unsigned long height = 0; unsigned long width = 0; using namespace std; using namespace cv; int findmax(long *p, int n) { int mx = 0, v = p[0]; for (int i = 1; i < n; i++) { if (p[i] > v) { v = p[i]; mx = i; } } return mx; } int main(int argc, char **argv ) { string usage = "derive-background -i -o "; string output_file; string inputFileName; int c; while ((c = getopt (argc, argv, "i:o:h")) != -1) switch (c) { case 'i': inputFileName = optarg; break; case 'o': output_file = optarg; break; case 'h': cout << usage << endl; exit(EXIT_FAILURE); break; default: break; } if( inputFileName.empty() || output_file.empty() ) { cout << usage << endl; exit(EXIT_FAILURE); } // Okay Declare all our working variables here. IplImage *first_image = NULL; IplImage *output_image = NULL; unsigned int i = 0; unsigned int j = 0; unsigned int k = 0; string filename; // open first image in input_file to deterimine the height and width ifstream input_file(inputFileName.c_str()); if (input_file.fail() ) { cerr << "cannot open the input file that contains name of the input images\n"; exit(EXIT_FAILURE); } // Read first line for our first image and rewind getline(input_file, filename); first_image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_UNCHANGED); if(!first_image) { cerr << "couldn't read first image" << endl; exit(1); } height = first_image->height; width = first_image->width; cvReleaseImage(&first_image); if (height == 0 || width == 0) { cerr << "height or width = 0!" << endl; exit(1); } cout << "height: " << height << " width: " << width << endl; // count number of images we have in the file input_file.clear(); input_file.seekg(0); while (!getline(input_file, filename).eof()) { nImages++; } cout << "number of images: " << nImages << endl; // initialize the storage arrays 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); } input_file.clear(); input_file.seekg(0); while (!getline(input_file, filename).eof()) { IplImage *input_image = NULL; input_image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_UNCHANGED); cout << "reading: " << filename << endl; for (i=0; i