#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; int findmax (uint8_t *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; } using namespace std; using namespace cv; 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); } IplImage *first_image, *input_image, *output_image; int i,j, k; int image = 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 input_file>>filename; // input_file.seekg (0, ios::beg); cout << filename << endl; first_image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_UNCHANGED); if(!first_image) { cerr << "couldn't read first image" << endl; exit(1); } // Get our height and width int height = first_image->height; int width = first_image->width; 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(input_file>>filename) { nImages++; } cout << "number of images: " << nImages << endl; // initialize the storage arrays uint8_t * array = (uint8_t *)malloc(nImages*height*width*3*sizeof(uint8_t)); if(array == NULL) { cerr << "could not allocate the proper memory, sorry!" << endl; exit(EXIT_FAILURE); } input_file.clear(); input_file.seekg(0); while (input_file>>filename) { input_image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_UNCHANGED); cout << "Image number " << image << "Filename " << filename << endl; for (j=0; j