简体   繁体   English

如何使用EmguCV将C#中的Mat转换为bitmap?

[英]How to convert Mat to bitmap in C# using EmguCV?

I'm trying to convert Mat to bitmap to open my webcam but with no success.我正在尝试将 Mat 转换为 bitmap 以打开我的网络摄像头,但没有成功。 However, I've seen a question with the same context compared to this question but without any answer from the other users: question ,但是,与此问题相比,我看到了一个具有相同上下文的问题,但其他用户没有任何回答: 问题

This is the code used:这是使用的代码:

  private void OpenWebcam_Click(object sender, RoutedEventArgs e)
    
    {
        var capture = new Emgu.CV.VideoCapture();

        using (var nextFrame = capture.QueryFrame()) 
        {
            if (nextFrame != null)
            {
                image.Source = nextFrame.ToBitmap(); // error here because there is no ToBitmap method
            }
        }

    }

Note that the code I've found in this question How to get video stream from webcam in emgu cv?请注意,我在这个问题How to get video stream from webcam in emgu cv? 中找到的代码? seems to have worked, but I'm using a new version so the method was deleted.似乎有效,但我使用的是新版本,因此该方法已被删除。

I've solved this problem after installing: Emgu.UI.windows and now, this code works for me:安装后我已经解决了这个问题: Emgu.UI.windows现在,这段代码对我有用:

 var bitmap = Emgu.CV.BitmapExtension.ToBitmap(nextFrame);

Simply install Emgu.CV.Bitmap nuget package and use it like following:只需安装 Emgu.CV.Bitmap nuget package 并按如下方式使用它:

myimage.ToBitmap()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM