/* * MainApplication.cpp * * Created on: 2011-03-09 * Author: JAWORA */ #include #include #include #include using namespace std; using namespace cv; int main(int argc, char **argv) { if (argc != 3) { cout << argv[0] << " imageFile partSize"; return 0; } // source image IplImage *source = cvLoadImage(argv[1], 1); int roiSize = atoi(argv[2]); int partCount = 0; for(int j = 0; j < source->width/roiSize + 1; ++j) { for(int i = 0; i < source->height/roiSize + 1; ++i) { cvSetImageROI(source, cvRect(i*roiSize, j*roiSize, (i*roiSize > source->width ? source->width % roiSize : roiSize), (j*roiSize > source->height ? source->height % roiSize : roiSize))); // cropped image IplImage *cropSource = cvCreateImage(cvGetSize(source), source->depth, source->nChannels); // copy cvCopy(source, cropSource, NULL); // ... do what you want with your cropped image ... stringstream fileName; fileName << "out" << partCount << ".jpg"; cvSaveImage(fileName.str().c_str(), cropSource); partCount++; // always reset the ROI cvResetImageROI(source); } } return 0; }