Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

c# - 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.

I've been trying a lot of things to get images from the webcam using as less CPU as possible:

But none of them were fine... Either way too slow or too CPU resources consuming.

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>

And the code behind:

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();
    }
}

My guess was to use BitmapSource/WriteableBitmap but I did not get them working...

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Image Class has got a UriSource property that you may be looking for


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...