Ask Your Question

how to insert a small size image on to a big image

asked 2014-07-19 00:32:35 -0500

user925 gravatar image

updated 2018-02-10 08:17:40 -0500

I have been successful in inserting text on to the big image but when it comes to inserting an image on to the big image, i am failing again and again. Here is my code of inserting text on to the big image:

int fr=1,i=1;
char name[20],s[20],smiley[20];
Mat image;

image = imread(name,CV_LOAD_IMAGE_COLOR);   // Read the file

if(! )                              // Check for invalid input   
cout <<  "Could not open or find the image" << std::endl ;
return -1;
if((i>=1 && i<=100)||(i>=201 && i<=300) || (i>=401 && i<=500)||(i>=601&& i<=700))
putText(image, "HAPPY", cvPoint(80,80), 
FONT_HERSHEY_COMPLEX_SMALL, 1, cvScalar(800,800,950), 1, CV_AA);
if((i>=101 && i<=200)||(i>=301 && i<=400) || (i>=501 && i<=600)||(i>=701&& i<=800))
putText(image, "SAD", cvPoint(80,80), 
FONT_HERSHEY_COMPLEX_SMALL, 1, cvScalar(800,800,950), 1, CV_AA);    
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image );                   // Show our image inside it.

waitKey(0);                                          // Wait for a keystroke in the window           
return 0;


Please help in inserting an image on to the big image.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-19 09:19:17 -0500

updated 2014-07-19 09:20:44 -0500

Hi there,

Let me illustrate this with an example: lets say that you have a small image and you want to insert it at the point (x,y) of your "big image": you can do something like this:

cv::Mat small_image;
cv::Mat big_image;
//Somehow fill small_image and big_image with your data
small_image.copyTo(big_image(cv::Rect(x,y,small_image.cols, small_image.rows)));

With this what you are doing is to create a ROI (region of interest) on your big image located at point (x,y) and of the same size as small_image. Then you copy the small_image into that ROI.

edit flag offensive delete link more


hey, thanks a lot for replying and give the solution. It really worked!!!

user925 gravatar imageuser925 ( 2014-07-23 09:24:46 -0500 )edit

Make sure both images are of same type. You cannot copy grayscale image to color image this way.

saurabheights gravatar imagesaurabheights ( 2015-11-30 04:39:52 -0500 )edit

Does this also work with getRectSubPix-ROIs? Will OpenCV handle the interpolation, when I copy or add to a sub pixel ROI?

GruenSein gravatar imageGruenSein ( 2018-07-21 04:05:40 -0500 )edit

Question Tools


Asked: 2014-07-19 00:32:35 -0500

Seen: 62,056 times

Last updated: Jul 23 '14