using System.Drawing;
using System.IO;
using OpenCvSharp.CPlusPlus;

namespace ImageProcessing
{
    public static class Extensions
    {
        public static Point2f ToFloat(this Point2d point)
        {
            return new Point2f((float)point.X, (float)point.Y);
        }

        public static Point2d ToDouble(this Point2f point)
        {
            return new Point2d(point.X, point.Y);
        }

        public static Bitmap ToBitmap(this Mat mat)
        {
            Bitmap bitmap = null;
            using (MemoryStream m = new MemoryStream())
            {
                mat.ToMemoryStream(".png").WriteTo(m);
                var bytes = ((MemoryStream)m).ToArray();
                System.IO.Stream inputStream = new MemoryStream(bytes);
                bitmap = new Bitmap(inputStream);
            }
            mat.Dispose();
            return bitmap;
        }
    }
}
