Combining a matrix image.

asked 2016-04-02 16:47:04 -0600

Restomix gravatar image

updated 2016-04-03 03:01:43 -0600


I want to combine two images into one.
Combine only image, without background(.png)
Paste the image at coordinates.

If somewhere pixels overlap with the previous picture, inform( return -1;)

EXAMPLE:

Image1(a matrix):
101
001
Image1(a matrix):
01
00
Image1+Image2(through the point A(0;0))
111
001
Image1+Image2(through the point C(1;0))
Error.Because, images intersect in point X(3;0)
Help please. I will be very grateful. I am Newbie in openCv, it's all that I have done:

  Mat stamps(char* name)
    {
   Mat src = imread(name, 1);
    Mat dst;//(src.rows,src.cols,CV_8UC4);
    Mat tmp, alpha;

    cvtColor(src, tmp, CV_BGR2GRAY);
    threshold(tmp, alpha, 100, 255, THRESH_BINARY);

    Mat rgb[3];
    split(src, rgb);

    Mat rgba[4] = { rgb[0], rgb[1], rgb[2], alpha };
    merge(rgba, 4, dst);
    return dst;
    }
    int main()
    {
    Mat image1=imread("...name");//in
    Mat image2 =stamps("....name");//from
    int x=0,y=0;
    image2.copyTo(dst.rowRange(y, y + image2.size().height).colRange(x, x + image2.size().width));
    }

//result with background image description

edit retag flag offensive close merge delete

Comments

2

imread("...name") loads a 3-channel image, your stamps() output has 4, now look at the error , again.

berak gravatar imageberak ( 2016-04-03 01:19:30 -0600 )edit

You are right, thank.But how to check whether they intersect?

Restomix gravatar imageRestomix ( 2016-04-03 02:01:56 -0600 )edit

To check whether 2 images intersect you need to compare coordinates, take a look here.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-04 03:58:50 -0600 )edit