我目前正在开发一个使用面部识别的项目.因此,我需要一种方法向用户显示网络摄像头图像,以便他可以调整他的脸部.
我一直在尝试使用尽可能少的CPU来从网络摄像头获取图像:
但它们都不是很好......无论是太慢还是太耗费CPU资源.
然后我尝试了Emgu库,我觉得很棒.起初,我在Windows窗体项目中尝试了它,并在图片框中更新图像.但是,当我试图将它集成到我的WPF项目中时,我遇到了如何将我的图像传递给我的Image控件的问题.
现在,我有以下源代码:
<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>
Run Code Online (Sandbox Code Playgroud)
而背后的代码:
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(); …Run Code Online (Sandbox Code Playgroud)