Ask Your Question
0

Why image is not copied to right part of collage image?

asked 2019-05-17 02:12:47 -0500

theateist gravatar image

updated 2019-05-17 02:13:10 -0500

I'm trying to create a collage image. The following code writes correctly to the left part of collage image (green), but not to the right.

Size collageSize(img1.width + img2.width, std::max(img1.height, img2.height));
Mat collageImg = Mat(collageSize, CV_8UC3, Scalar::all(0));

Mat img1ROI(collageImg, cv::Range(0, img1.rows), cv::Range(0, img1.cols));
rectangle(img1ROI, Rect(0, 0, img1.cols, img1.rows), CV_RGB(0, 255, 0), -1);

Mat img2ROI(collageImg, cv::Range(0, img2.rows), cv::Range(img1.cols, img2.cols));
rectangle(img2ROI, Rect(0, 0, img2.cols, img2.rows), CV_RGB(255, 0, 0), -1);

image description

If I create img2ROI as following:

Mat img2ROI(collageImg, Rect(img1.cols, 0, img2.cols, img2.rows));

Then I get the correct collage image: image description

Why it doesn't work with Range for the right image?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-05-17 06:48:44 -0500

berak gravatar image

updated 2019-05-17 06:51:23 -0500

maths error,

cv::Range(img1.cols, img2.cols)

is empty, if img1.cols == img2.cols

you probably wanted something like:

cv::Range(img1.cols, collageImg.cols)
edit flag offensive delete link more

Comments

Stupid mistake :) Thanks!

theateist gravatar imagetheateist ( 2019-05-19 11:59:33 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-17 02:12:47 -0500

Seen: 18 times

Last updated: 2 days ago