Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

here's how you *should * do that:

Mat big(4800, 4800, CV_8UC3, Scalar(200,100,55)); // for demo purpose

int patchSize = 300;
vector<Mat> patches;

// make sure, it fits !
CV_Assert(big.rows % patchSize == 0);
CV_Assert(big.cols % patchSize == 0);

for (int i=0; i<big.rows; i+=patchSize) {
    for (int j=0; j<big.cols; j+=patchSize) {
        patches.push_back(big(Rect(i, j, patchSize, patchSize)));
    }
}

here's how you *should * do that:

Mat big(4800, 4800, CV_8UC3, Scalar(200,100,55)); // for demo purpose

int patchSize = 300;
vector<Mat> patches;

// make sure, it fits !
CV_Assert(big.rows % patchSize == 0);
CV_Assert(big.cols % patchSize == 0);

for (int i=0; i<big.rows; i<big.cols; i+=patchSize) {
    for (int j=0; j<big.cols; j<big.rows; j+=patchSize) {
        patches.push_back(big(Rect(i, j, patchSize, patchSize)));
    }
}

It may seem a super-banal task. indeed, it is, here's how you *should * do that:

Mat big(4800, 4800, CV_8UC3, Scalar(200,100,55)); // for demo purpose

int patchSize = 300;
vector<Mat> patches;

// make sure, it fits !
CV_Assert(big.rows % patchSize == 0);
CV_Assert(big.cols % patchSize == 0);

for (int i=0; i<big.cols; i+=patchSize) {
    for (int j=0; j<big.rows; j+=patchSize) {
        patches.push_back(big(Rect(i, j, patchSize, patchSize)));
    }
}

It may seem a super-banal task. task.

indeed, it is, here's how you *should * do that:

Mat big(4800, 4800, CV_8UC3, Scalar(200,100,55)); // for demo purpose

int patchSize = 300;
vector<Mat> patches;

// make sure, it fits !
CV_Assert(big.rows % patchSize == 0);
CV_Assert(big.cols % patchSize == 0);

for (int i=0; i<big.cols; i+=patchSize) {
    for (int j=0; j<big.rows; j+=patchSize) {
        patches.push_back(big(Rect(i, j, patchSize, patchSize)));
    }
}