OpenCvImageAlgorihm.cs 863 B

12345678910111213141516171819202122232425262728293031
  1. using OpenCvSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace MvvmScaffoldFrame48.DLL.ImageAlgorithm
  11. {
  12. public static class OpenCvImageAlgorihm
  13. {
  14. /// <summary>
  15. /// 将Bitmap转换为Mat(输出为彩色图)
  16. /// 转换后的图像可以增加彩色框
  17. /// </summary>
  18. /// <param name="bitmap">源Bitmap</param>
  19. /// <returns>对应的Mat对象</returns>
  20. public static Mat BitmapToMat(Bitmap bitmap)
  21. {
  22. using (var ms = new MemoryStream())
  23. {
  24. bitmap.Save(ms, ImageFormat.Bmp);
  25. ms.Position = 0;
  26. return Mat.FromStream(ms, ImreadModes.Color);
  27. }
  28. }
  29. }
  30. }