c# OpenCV 不同尺寸图片叠加

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

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

 

posted on 2020-06-30 09:59  巴顿的博客  阅读(1236)  评论(0编辑  收藏  举报

导航