目标,在一张背景图片的指定位置指定区域叠加一张小孩的人像照。
1.在NuGet管理搜索OpenCV,选择下图所示,点安装
2.引用OpenCV
using OpenCvSharp;
3.上代码
Mat matBackground = new Mat(@"d:\bg.jpeg",ImreadModes.AnyColor); Mat matBoy = new Mat(@"d:\人像\10岁.jpg"); Rect rect = new Rect(10, 20, matBoy.Width, matBoy.Height); Mat matRectInBackground = new Mat(matBackground, rect); matBoy.CopyTo(matRectInBackground); Cv2.ImShow("Merge", matBackground); Cv2.WaitKey(); Console.WriteLine("Merged");
4.效果图