This is an example code to plot a small image on to a big image by using C# (for Format8bppIndexed only). I do not use OpenCV, however, you may write your own code in OpenCV with the hint inside this example.
private static Bitmap PlotSmallImageOnBigImage(Bitmap bigImage, Bitmap smallImage)
{
Rectangle r1 = new Rectangle(0, 0, bigImage.Width, bigImage.Height);
Rectangle r2 = new Rectangle(0, 0, smallImage.Width, smallImage.Height);
if (r1.Contains(r2) == false)
throw new Exception("ERROR: small image must be inside the big image.");
int offsetWidth = (bigImage.Width-smallImage.Width)/2;
int offsetHeight = (bigImage.Height-smallImage.Height)/2;
Rectangle rect = new Rectangle(offsetWidth, offsetHeight, smallImage.Width, smallImage.Height);
BitmapData bigData = bigImage.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
BitmapData smallData=smallImage.LockBits(new Rectangle(0,0, smallImage.Width, smallImage.Height), ImageLockMode.ReadOnly,
PixelFormat.Format8bppIndexed);
unsafe
{
byte* ptrB = (byte*)(void*)bigData.Scan0;
int offsetB = bigData.Stride - rect.Width * 1;
byte* ptrS = (byte*)(void*)smallData.Scan0;
int offsetS = smallData.Stride - smallData.Width * 1;
for (int y = 0; y < rect.Height; y++)
{
for (int x = 0; x < rect.Width; x++)
{
ptrB[0] = ptrS[0];
ptrB++;
ptrS++;
}
ptrB += offsetB;
ptrS += offsetS;
}
}
bigImage.UnlockBits(bigData);
smallImage.UnlockBits(smallData);
return bigImage;
}