How to display webcam images captured with Emgu?

前端 未结 7 924
北恋
北恋 2020-12-10 14:18

I\'m currently working on a project that use Facial Recognition. I therefore need a way to display the webcam images to the user so he can adjust his face.

I\'ve bee

7条回答
  •  伪装坚强ぢ
    2020-12-10 15:10

    I believe you have to use interop (source):

    using System.Windows.Interop;
    using System.Windows.Media.Imaging;
    
    public static ImageSource AsImageSource(
        this Image image) where TColor : IColor, new()
    {
        return Imaging.CreateBitmapSourceFromHBitmap(image.Bitmap.GetHbitmap(),
                           IntPtr.Zero, Int32Rect.Empty,
                           BitmapSizeOptions.FromEmptyOptions());
    }
    

    Which could be used like this:

    void timer_Elapsed(object sender, ElapsedEventArgs e)
    {
            using (Image frame = capture.QueryFrame())
            {
                    if (frame != null)
                    {
                            var bmp = frame.AsImageSource();
                    }
            }
    }
    

    If the interop doesn't perform well enough, take a look at the source of Image.ToBitmap and Image.get_Bitmap to see how you could implement your own WriteableBitmap.

提交回复
热议问题