c# OpenCV 不同尺寸图片叠加

时间:2020-06-30 11:02:00   收藏:0   阅读:84

目标,在一张背景图片的指定位置指定区域叠加一张小孩的人像照。

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.效果图

技术图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!