void cvOverlayImage(IplImage* src, IplImage* overlay, CvPoint location, CvScalar S, CvScalar D)
{
int x,y,i;
for(x=0;x < overlay->width -10;x++)
//replace '-10' by whatever x position you want your overlay image to begin.
//say '-varX'
{
if(x+location.x>=src->width) continue;
for(y=0;y < overlay->height -10;y++)
//replace '-10' by whatever y position you want your overlay image to begin.
//say '-varY'
{
if(y+location.y>=src->height) continue;
CvScalar source = cvGet2D(src, y+location.y, x+location.x);
CvScalar over = cvGet2D(overlay, y, x);
CvScalar merged;
for(i=0;i<4;i++)
merged.val[i] = (S.val[i]*source.val[i]+D.val[i]*over.val[i]);
cvSet2D(src, y+location.y, x+location.x, merged);
}
}
}
To use it
cvOverlayImage(largerimage, overlayimage, cvPoint(10, 10), cvScalar(0.5,0.5,0.5,0.5), cvScalar(0.5,0.5,0.5,0.5));
//The cvPoint(10,10) can be the cvPoint(varX,varY) depending on how you write the function
//and how you want to use it.
//You cannot choose values less than 'varX' and 'varY' in this case
//else you would see a runtime error.