Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

here's my idea:

void tile(const vector<Mat> &src, Mat &dst, int grid_x, int grid_y) {
    // patch size
    int width  = dst.cols/grid_x;
    int height = dst.rows/grid_y;
    // iterate through grid
    int k = 0;
    for(int i = 0; i < grid_y; i++) {
        for(int j = 0; j < grid_x; j++) {
            Mat s = src[k++];
            resize(s,s,Size(width,height));
            s.copyTo(dst(Rect(j*width,i*height,width,height)));
        }
    }
}

int main(int argc, char **argv)
{

    Mat img;

    namedWindow("image", WINDOW_NORMAL);
    int gridx=4, gridy=4;
    vector<Mat> vec;
    VideoCapture cap(0);
    for(;;)
    {
        cap >> img;
        vec.push_back(img);
        imshow("image", img); 
        char k = (char) waitKey(10);
        if ( vec.size() == gridx*gridy ) 
            break;
    }
    Mat res = Mat(480,640,CV_8UC3);
    tile(vec,res,gridx,gridy);
    imshow("image",res);
    waitKey(0);
    return 0;
}