如何显示与Emgu摄像头拍摄的图像? [英] How to display webcam images captured with Emgu?
问题描述
我目前正在使用人脸识别的项目。
,因此我需要一种方法来显示图像的摄像头给用户,因此他可以调整他的脸。
I'm currently working on a project that use Facial Recognition. I therefore need a way to display the webcam images to the user so he can adjust his face.
我已经尝试了很多事情来获得由于使用更少的CPU尽量从摄像头的图像:
I've been trying a lot of things to get images from the webcam using as less CPU as possible:
- VideoRendererElement
- WPFMediaKit
- DirectShow-Lib
但没有他们都是很好...无论哪种方式速度太慢或者太CPU资源消耗。
But none of them were fine... Either way too slow or too CPU resources consuming.
然后我试过的Emgu库,我感觉棒极了。
起初,我试图在Windows窗体项目和正在更新的图像的图片框的。
但是,当我试图将它集成在我的WPF项目我被困在如何..
Then I tried the Emgu library and I felt great about it. At first, I tried it in a Windows Form project and was updating the image in a Picture Box. But then, when I tried to integrate it in my WPF Project I got stuck on how to pass my image to my Image control..
现在我的形象传递给我的图像控制,我有以下代码:
Right now, I've the following source code:
<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的,但我没有不能让他们的工作...
My guess was to use BitmapSource/WriteableBitmap but I did not get them working...
谢谢!
推荐答案
我估计你正在寻找的是这样的:
I reckon all you're looking for is this:
Image<Bgr, Byte> frame = capture.QueryFrame();
pictureBox1.Image = image.ToBitmap(pictureBox1.Width, pictureBox1.Height);
这篇关于如何显示与Emgu摄像头拍摄的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!