问题
I need to put a smaller image within a larger image. the smaller picture should be centered in the larger picture. I'm working with C# and OpenCV, does anyone know how to do this?
回答1:
There is a helpful post on watermarking images that might help you out. I assume it is pretty close to the same process to what you are doing.
Also, be sure to check this article at CodeProject for another example using GDI+.
回答2:
check this post. same problem, same solution. Code is for C++ but you can work it out.
回答3:
this worked for me
LargeImage.ROI = SearchArea; // a rectangle
SmallImage.CopyTo(LargeImage);
LargeImage.ROI = Rectangle.Empty;
EmguCV of course
回答4:
The above answer is great! Here's a complete method that adds the watermark to the lower right corner.
public static Image<Bgr,Byte> drawWaterMark(Image<Bgr, Byte> img, Image<Bgr, Byte> waterMark)
{
Rectangle rect;
//rectangle should have the same ratio as the watermark
if (img.Width / img.Height > waterMark.Width / waterMark.Height)
{
//resize based on width
int width = img.Width / 10;
int height = width * waterMark.Height / waterMark.Width;
int left = img.Width - width;
int top = img.Height - height;
rect = new Rectangle(left, top, width, height);
}
else
{
//resize based on height
int height = img.Height / 10;
int width = height * waterMark.Width / waterMark.Height;
int left = img.Width - width;
int top = img.Height - height;
rect = new Rectangle(left, top, width, height);
}
waterMark = waterMark.Resize(rect.Width, rect.Height, Emgu.CV.CvEnum.INTER.CV_INTER_AREA);
img.ROI = rect;
Image<Bgr, Byte> withWaterMark = img.Add(waterMark);
withWaterMark.CopyTo(img);
img.ROI = Rectangle.Empty;
return img;
}
来源:https://stackoverflow.com/questions/12787153/putting-a-smaller-image-within-a-larger-image