EmguCV在图像标签C#WPF中显示垫子

EmguCV在图像标签C#WPF中显示垫子,c#,wpf,opencv,emgucv,C#,Wpf,Opencv,Emgucv,有没有办法在c#中显示WPF图像标记内的Mat对象 另外,是否有一种方法可以在画布/图像标记内绘制图像,而不是在Imshow打开的新窗口上绘制 CvInvoke.Imshow("ponaredek", slika); 最后,对于乞丐来说,哪一个更好?EmguCV或常规openCV?如果要显示在WPF内部读取的图像,可以使用Xaml中的图像源。您应该将Mat对象转换为位图,然后将位图转换为图像源对象,因为这将需要显示图像。这里的表格详细介绍了如何做到这一点 首先将Mat对象转换为位图 //Con

有没有办法在c#中显示WPF图像标记内的Mat对象

另外,是否有一种方法可以在画布/图像标记内绘制图像,而不是在Imshow打开的新窗口上绘制

CvInvoke.Imshow("ponaredek", slika);

最后,对于乞丐来说,哪一个更好?EmguCV或常规openCV?

如果要显示在WPF内部读取的图像,可以使用Xaml中的图像源。您应该将Mat对象转换为位图,然后将位图转换为图像源对象,因为这将需要显示图像。这里的表格详细介绍了如何做到这一点

首先将Mat对象转换为位图

//Convert the Mat object to a bitmap
Bitmap img = image.ToBitmap();

//Using the method below, convert the bitmap to an imagesource
imgOutput.Source = ImageSourceFromBitmap(img);
我上面调用的函数可以通过下面的代码实现

//If you get 'dllimport unknown'-, then add 'using System.Runtime.InteropServices;'
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteObject([In] IntPtr hObject);

public ImageSource ImageSourceFromBitmap(Bitmap bmp)
{
    var handle = bmp.GetHbitmap();
    try
    {
        return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    }
    finally { DeleteObject(handle); }               
}

您将不得不为您的项目添加一些引用,但这种方法在过去对我有效。至于在图像上绘图,我不确定如何实现这一点,因为每次鼠标移动时,您都必须更新图像上的绘图,这需要包含一些鼠标事件参数。

EmguCV是openCV**的包装器,用于**C#(.Net langs)此代码是否使用默认openCV?因为EmguCV Mat没有ToBitmap()方法,所以它应该有,所以您使用的是哪个版本的EmguCV?此外,为了在c#中使用位图,还必须包含另一个引用。我在下面编写的代码只与Emgucv和c#兼容,而与opencv不兼容。
//If you get 'dllimport unknown'-, then add 'using System.Runtime.InteropServices;'
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteObject([In] IntPtr hObject);

public ImageSource ImageSourceFromBitmap(Bitmap bmp)
{
    var handle = bmp.GetHbitmap();
    try
    {
        return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    }
    finally { DeleteObject(handle); }               
}