Revision 91,
1.3 KB
checked in by mcichenski, 14 years ago
(diff) |
CMake project for simple application that cuts image into smaller parts, requires OpenCV
|
Rev | Line | |
---|
[91] | 1 | /* |
---|
| 2 | * MainApplication.cpp |
---|
| 3 | * |
---|
| 4 | * Created on: 2011-03-09 |
---|
| 5 | * Author: JAWORA |
---|
| 6 | */ |
---|
| 7 | #include <iostream> |
---|
| 8 | #include <opencv2/core/core.hpp> |
---|
| 9 | #include <opencv2/imgproc/imgproc.hpp> |
---|
| 10 | #include <opencv2/highgui/highgui.hpp> |
---|
| 11 | |
---|
| 12 | using namespace std; |
---|
| 13 | using namespace cv; |
---|
| 14 | |
---|
| 15 | int main(int argc, char **argv) { |
---|
| 16 | if (argc != 3) |
---|
| 17 | { |
---|
| 18 | cout << argv[0] << " imageFile partSize"; |
---|
| 19 | return 0; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | // source image |
---|
| 23 | IplImage *source = cvLoadImage(argv[1], 1); |
---|
| 24 | |
---|
| 25 | int roiSize = atoi(argv[2]); |
---|
| 26 | int partCount = 0; |
---|
| 27 | for(int j = 0; j < source->width/roiSize + 1; ++j) { |
---|
| 28 | for(int i = 0; i < source->height/roiSize + 1; ++i) { |
---|
| 29 | cvSetImageROI(source, cvRect(i*roiSize, j*roiSize, |
---|
| 30 | (i*roiSize > source->width ? source->width % roiSize : roiSize), |
---|
| 31 | (j*roiSize > source->height ? source->height % roiSize : roiSize))); |
---|
| 32 | |
---|
| 33 | // cropped image |
---|
| 34 | IplImage *cropSource = cvCreateImage(cvGetSize(source), source->depth, source->nChannels); |
---|
| 35 | |
---|
| 36 | // copy |
---|
| 37 | cvCopy(source, cropSource, NULL); |
---|
| 38 | |
---|
| 39 | // ... do what you want with your cropped image ... |
---|
| 40 | stringstream fileName; |
---|
| 41 | fileName << "out" << partCount << ".jpg"; |
---|
| 42 | cvSaveImage(fileName.str().c_str(), cropSource); |
---|
| 43 | partCount++; |
---|
| 44 | |
---|
| 45 | // always reset the ROI |
---|
| 46 | cvResetImageROI(source); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | return 0; |
---|
| 51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.