gpt4 book ai didi

c# - 如何显示使用 Emgu 捕获的网络摄像头图像?

转载 作者:可可西里 更新时间:2023-11-01 09:06:56 24 4
gpt4 key购买 nike

我目前正在从事一个使用面部识别的项目。因此,我需要一种方法来向用户显示网络摄像头图像,以便他可以调整自己的面部。

我已经尝试了很多方法来使用尽可能少的 CPU 从网络摄像头获取图像:

但它们都不是很好......要么太慢要么太消耗 CPU 资源。

然后我尝试了 Emgu library我感觉很好。起初,我在 Windows 窗体项目中尝试过,并在 Picture Box 中更新图像。但是,当我试图将它集成到我的 WPF 项目中时,我陷入了如何将我的图像传递到我的图像控件的问题中。

现在,我有以下源代码:

<Window x:Class="HA.FacialRecognition.Enroll.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Width="800" Height="600"
Loaded="Window_Loaded" Closing="Window_Closing">
<Grid>
<Image x:Name="webcam" Width="640" Height="480" >
<Image.Clip>
<EllipseGeometry RadiusX="240" RadiusY="240">
<EllipseGeometry.Center>
<Point X="320" Y="240" />
</EllipseGeometry.Center>
</EllipseGeometry>
</Image.Clip>
</Image>
</Grid>
</Window>

以及背后的代码:

private Capture capture;
private System.Timers.Timer timer;

public Window1()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
capture = new Capture();
capture.FlipHorizontal = true;

timer = new System.Timers.Timer();
timer.Interval = 15;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Start();
}

void timer_Elapsed(object sender, ElapsedEventArgs e)
{
using (Image<Bgr, byte> frame = capture.QueryFrame())
{
if (frame != null)
{
var bmp = frame.Bitmap;
// How do I pass this bitmap to my Image control called "webcam"?
}
}
}

private void Window_Closing(object sender, CancelEventArgs e)
{
if (capture != null)
{
capture.Dispose();
}
}

我的猜测是使用 BitmapSource/WriteableBitmap 但我没有让它们工作...

谢谢!

最佳答案

Image 类具有您可能正在寻找的 UriSource 属性

关于c# - 如何显示使用 Emgu 捕获的网络摄像头图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com