2019年11月22日 星期五

emgu (4.1.1.3497) WPF example 2019/11/23

Ref: https://github.com/emgucv/emgucv/tree/master/Emgu.CV.Example/WPF

1. Visual Studio 2017 @ Windows 10 x64 @ ASUS X450J
2. emgu WPF example
3. failure : mat to image.source
    image1.Source = image.ToBitmapSource();
4. 轉換 mat to image.imagesource @ WPF
https://frasergreenroyd.com/how-to-convert-opencv-cvmat-to-system-bitmap-to-system-imagesource/
         private void image1_Initialized(object sender, EventArgs e)
        {
            Mat image = new Mat(100, 400, DepthType.Cv8U, 3);
            image.SetTo(new Bgr(255, 255, 255).MCvScalar);
            CvInvoke.PutText(image, "Hello, world", new System.Drawing.Point(10, 50),           Emgu.CV.CvEnum.FontFace.HersheyPlain, 3.0, new Bgr(255.0, 0.0, 0.0).MCvScalar);
            image1.Source = ConvertBitmapToImageSource(image.Bitmap); //.ToBitmapSource();
        }

        private ImageSource ConvertBitmapToImageSource(Bitmap imToConvert)
        {
            Bitmap bmp = new Bitmap(imToConvert);
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            BitmapImage image = new BitmapImage();
            image.BeginInit();
            ms.Seek(0, SeekOrigin.Begin);
            image.StreamSource = ms;
            image.EndInit();
            ImageSource sc = (ImageSource)image;
            return sc;
        }

沒有留言:

張貼留言