Ask Your Question
1

overlay smaller image over bigger image in a particular area

asked 2014-08-21 04:38:05 -0600

borjaevo gravatar image

Hi,

I'm trying to overlay a smaller image into bigger image in a concrete area. With images of same size i have no problems, but when call to add function size and type of both images have to be the same. Other problem is, first of all i black out the area where i will paste the other image but this is not very efficient. I would like to know if are there another ways to do it.

Thanks and sorry for my english.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-08-21 04:50:18 -0600

berak gravatar image

if smallImg and bigImg have the same format, and you're sure it 'fits' at the given position, try:

 smallImg.copyTo( bigImg.submat( y, smallImg.rows(), x, smallImg.cols() ) );
edit flag offensive delete link more

Comments

Thank you! i'll try

borjaevo gravatar imageborjaevo ( 2014-08-21 04:52:53 -0600 )edit
0

answered 2020-06-30 15:03:31 -0600

copyTo is the correct approach, however be mindful that the function will fail without warning in many cases. A common pitfall is if you try to copy an RGBa image into GBR or vice versa

var selectedArea = RGBaImgToDisplay.submat(resultRect)
sampleImageColor.copyTo(selectedArea)

will not work, unless you first make sure that sampleImageColor is also an RGBa like so:

cvtColor(bgrImage, sampleImageColor, Imgproc.COLOR_BGR2RGBA);

Then it works as expected

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-08-21 04:38:05 -0600

Seen: 4,599 times

Last updated: Aug 21 '14