EmguCV 在图像标签 C# WPF 中显示 Mat
EmguCV show Mat in Image tag C# WPF
有没有办法在 C# 中的 WPF 图像标记内显示 Mat 对象?
Mat image= CvInvoke.Imread(op.FileName, Emgu.CV.CvEnum.ImreadModes.AnyColor);
另外,有没有办法在 canvas/image 标签内的图像上绘制,而不是在 Imshow 打开的新 window 上绘制?
CvInvoke.Imshow("ponaredek", slika);
最后,对于初学者来说,哪个更好用? EmguCV 还是常规的 openCV?
如果您想显示您在 WPF 中读取的图像,那么您可以使用图像源,它位于 Xaml 中。您应该将 Mat 对象转换为位图,然后将位图转换为图像源对象,因为显示图像需要这样做。 stack 此处的表格详细说明了如何执行此操作。
首先将您的 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); }
}
您将不得不添加一些对项目的引用,但这种方法过去对我有用。至于在图像上绘图,我不确定如何完成此操作,因为每次鼠标移动时您都必须更新图像上的绘图,这必须包含一些鼠标事件参数。
有没有办法在 C# 中的 WPF 图像标记内显示 Mat 对象?
Mat image= CvInvoke.Imread(op.FileName, Emgu.CV.CvEnum.ImreadModes.AnyColor);
另外,有没有办法在 canvas/image 标签内的图像上绘制,而不是在 Imshow 打开的新 window 上绘制?
CvInvoke.Imshow("ponaredek", slika);
最后,对于初学者来说,哪个更好用? EmguCV 还是常规的 openCV?
如果您想显示您在 WPF 中读取的图像,那么您可以使用图像源,它位于 Xaml 中。您应该将 Mat 对象转换为位图,然后将位图转换为图像源对象,因为显示图像需要这样做。 stack 此处的表格详细说明了如何执行此操作。
首先将您的 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); }
}
您将不得不添加一些对项目的引用,但这种方法过去对我有用。至于在图像上绘图,我不确定如何完成此操作,因为每次鼠标移动时您都必须更新图像上的绘图,这必须包含一些鼠标事件参数。