Ask Your Question
1

Make a collage with other images

asked 2013-06-21 14:18:53 -0500

yes123 gravatar image

updated 2013-06-21 14:20:52 -0500

I have a vector<Mat> with images with different size.

Then I have a bigger image (let's say 640x480) I want to make a grid collage like this:

image description

With variable numbers of cols. How would you do that?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-06-22 03:09:00 -0500

berak gravatar image

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;
}
edit flag offensive delete link more
1

answered 2013-06-21 14:58:23 -0500

Guanta gravatar image

Think, this: http://answers.opencv.org/question/13876/read-multiple-images-from-folder-and-concat/ with some slight modifications is exactly what you need. You only need to resize your images beforehand. Good luck!

edit flag offensive delete link more

Comments

If I resize the image in images I don't need to check max_height and max_width like you do in your loop... But nyway I don't understand your second loop. Why do you parse every pixels (y<rows and x<cols). Also the given number of cols should be used to calculate the width to resize the inner images

yes123 gravatar imageyes123 ( 2013-06-21 15:07:18 -0500 )edit

you are right, in your case you don't need to find out the proper dimensions but to resize them. The other two loops are not a parsing of pixels but going through the rows/cols of your grid and copying the image to the appropriate location.

Guanta gravatar imageGuanta ( 2013-06-21 15:29:22 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-06-21 14:18:53 -0500

Seen: 4,421 times

Last updated: Jun 23 '13