Ask Your Question

Tile multiple images into one .bmp

asked 2015-11-13 13:48:40 -0600

KvltKitty gravatar image

updated 2020-08-13 14:51:24 -0600

Hello everyone,

I am trying to solve a relatively simple problem, but the opencv library seems stitching seems like it perhaps may be overkill for what I'm trying to accomplish. Essentially here's what I'm trying to do in a procedural RPG:

Generate tile types in the world

for each(tile){

-generate custom texture and output tile to a .bmp file
-take that tile and append it to a "FinalMap.bmp" file in the correct position


The second step is the only one that is causing me problems. When I try using Stitcher.stitch() it fails everytime. Is there a more simple solution to what I'm trying to do?? If anyone has a link to an example of this it'd be greatly appreciated

edit retag flag offensive close merge delete


noob question I know, but bump as I need help and can't find anything on this online

KvltKitty gravatar imageKvltKitty ( 2015-11-13 16:58:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-11-13 20:15:54 -0600

updated 2015-11-14 07:45:10 -0600

although there are many simple solution,i tried to write a simple class to solve your problem. i hope you like it.

i tried to explain how to use it by comments on the code.

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

class ImageCells
    ImageCells(int rows, int cols, int width, int height);
    virtual ~ImageCells() {}

    int cellwidth() const {return m_width;}
    int cellheight() const { return m_height;}
    int cols() const { return m_cols;}
    int rows() const { return m_rows;}

    void setCell( int col, int row, Mat img );
    void setImage( Mat img );
    Mat getCell( int col, int row );
    Mat image;

    int  m_width;
    int  m_height;
    int  m_cols;
    int  m_rows;

ImageCells::ImageCells( int rows, int cols, int width, int height)
    image = Mat::zeros( rows * height, cols * width, CV_8UC3);
    m_width = width;
    m_height = height;
    m_cols = cols;
    m_rows = rows;

void ImageCells::setCell( int col, int row, Mat img )
    if(img.cols == m_width & img.rows == m_height)
        Mat roi = image( Rect(col * m_width, row * m_height, m_width, m_height) );

Mat ImageCells::getCell( int col, int row )
    Mat roi = image( Rect(col * m_width, row * m_height, m_width, m_height) );
    return roi.clone();

void ImageCells::setImage( Mat img )
    if(img.cols >= image.cols & img.rows >= image.rows)

int main( int argc, char** argv )
    ImageCells cells(4,3,70,90); // it creates a ImageCells class having 4 rows and 3 cols, cell witdh = 70 cell height = 90 you can change these values according your needs

    Mat img = Mat( 90, 70, CV_8UC3,Scalar(0,0,255)); // a test mat to use with cells.setCell important note is : img witdh&height must be same to cell witdh&height

for(int i=0; i < cells.cols(); i++)
    for(int j =0; j < cells.rows(); j++ )
   cells.setCell(i,j,img); // here you see how to use  setCell
   randu(img,30*i,160*j); // to show purpose changes img

for(int i=0; i < cells.cols(); i++)
    for(int j =0; j < cells.rows(); j++ )
    imshow("cells",cells.getCell(i,j)); // here you see how to use  getCell
    return 0;
edit flag offensive delete link more


Thank you so much! Greatly appreciated, just woke up and looking over it now. :)

KvltKitty gravatar imageKvltKitty ( 2015-11-14 07:41:47 -0600 )edit

This is excellent, thank you thank you thank you. Very helpful. Opencv is so large that breaking into it has been a bit overwhelming. Thanks :D

KvltKitty gravatar imageKvltKitty ( 2015-11-14 08:01:52 -0600 )edit

glad to help you. i know it is open to some improvements. keep following this topic maybe i will add some features

sturkmen gravatar imagesturkmen ( 2015-11-14 08:41:41 -0600 )edit

@sturkmen add some image examples in order other people to be able to see what you have implemented here. As I have told in the past it is really helpful to have images showing what we are implementing ;-)

theodore gravatar imagetheodore ( 2015-11-15 07:26:41 -0600 )edit

Question Tools

1 follower


Asked: 2015-11-13 13:48:40 -0600

Seen: 1,957 times

Last updated: Nov 14 '15