欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 代码片段 - C#实现多张图片根据重叠部分拼接图像

代码片段 - C#实现多张图片根据重叠部分拼接图像

2025/4/17 4:39:33 来源:https://blog.csdn.net/qq_14853875/article/details/147049438  浏览:    关键词:代码片段 - C#实现多张图片根据重叠部分拼接图像

安装Nuget包

  • Emgu.CV
  • Emgu.CV.runtime.windows
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Stitching;
using Emgu.CV.Structure;
using Emgu.CV.Util;
using System.Diagnostics;
namespace Tools
{public class ImageStitcher{public static void StitchImages(string[] imagePaths, string stitchedImagePath){Image<Bgr, byte>[] sourceImages = new Image<Bgr, byte>[imagePaths.Length];for (int i = 0; i < sourceImages.Length; i++){sourceImages[i] = new Image<Bgr, byte>(imagePaths[i]);}try{//only use GPU if you have build the native binary from code and enabled "NON_FREE"using (Stitcher stitcher = new Stitcher())using (Emgu.CV.Features2D.AKAZE finder = new Emgu.CV.Features2D.AKAZE())using (Emgu.CV.Stitching.WarperCreator warper = new SphericalWarper()){stitcher.SetFeaturesFinder(finder);stitcher.SetWarper(warper);using (VectorOfMat vm = new VectorOfMat()){Mat result = new Mat();vm.Push(sourceImages);Stopwatch watch = Stopwatch.StartNew();Stitcher.Status stitchStatus = stitcher.Stitch(vm, result);watch.Stop();if (stitchStatus == Stitcher.Status.Ok){result.Save(stitchedImagePath);Console.WriteLine(string.Format("Stitched in {0} milliseconds.", watch.ElapsedMilliseconds));}else{Console.WriteLine(string.Format("Stiching Error: {0}", stitchStatus));}}}}finally{foreach (Image<Bgr, Byte> img in sourceImages){img.Dispose();}}}}
}
  • imagePaths:待拼接的图片路径列表
  • stitchedImagePath:拼接好的图片保存路径

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词