任务,等待网络摄像头 [英] Task, await with webcam

查看:99
本文介绍了任务,等待网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试编写支持网络摄像头的简单应用.我正在使用此库(我知道这是错误的,但现在我需要做很多更改:()http://easywebcam.codeplex.com/.

当我连接到摄像头时,用户界面的响应速度非常慢,当我从摄像头更改所需的fps时,效果会更好一些(我认为我的UI会得到与摄像头相同的效果).

我试图编写函数以获取线程中的帧,以使我的ui不会变慢.

异步void webcam_ImageCapturedAsync(对象源,WebcamEventArgs e)
        {
            _FrameImage.Source =等待Helper.LoadBitmapAsync((System.Drawing.Bitmap)e.WebCamImage);
        }

        无效的webcam_ImageCaptured(对象源,WebcamEventArgs e)
        {
            _FrameImage.Source = Helper.LoadBitmap((System.Drawing.Bitmap)e.WebCamImage);
        } 

 

还有

公共异步静态Task< BitmapSource> LoadBitmapAsync(System.Drawing.Bitmap源)
        {
            返回等待任务< BitmapSource> .Run(()=>
                {
                    ip = source.GetHbitmap();

                    bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip,IntPtr.Zero,System.Windows.Int32Rect.Empty,

                    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                    DeleteObject(ip);
                    
                    返回bs;
                });

        }
        公共静态BitmapSource LoadBitmap(System.Drawing.Bitmap源)
        {
            
                ip = source.GetHbitmap();

                bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip,IntPtr.Zero,System.Windows.Int32Rect.Empty,

                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                DeleteObject(ip);

                返回bs;

        } 

异步方法是我写的,其他方法来自库.

当我使用异步方法启动程序时,我的图像框保持灰色,在调试器中所有参数都出错.那么问题是为什么呢? :> 

解决方案

您说用户界面运行非常缓慢....

您正在使用什么方法?

请改用第一个定义的方法,这是一个异步方法,不会使您的UI崩溃;)


Hi, i'm trying to write simple app with webcam support. I'm using this library ( i know that was mistake but now i would have change some much :( ) http://easywebcam.codeplex.com/ .

When I'm connected to camera my UI respond very slow, when i change required fps from camera it's a little better ( i think my UI gets as much as the camera give).

I tried to write function that gets frames in thread so my ui don't slow down.

  async void webcam_ImageCapturedAsync(object source, WebcamEventArgs e)
        {
            _FrameImage.Source =await Helper.LoadBitmapAsync((System.Drawing.Bitmap)e.WebCamImage);
        }

        void webcam_ImageCaptured(object source, WebcamEventArgs e)
        {
            _FrameImage.Source = Helper.LoadBitmap((System.Drawing.Bitmap)e.WebCamImage);
        }

 

And

 public async static Task<BitmapSource> LoadBitmapAsync(System.Drawing.Bitmap source) 
        {
            return await Task<BitmapSource>.Run(() =>
                {
                    ip = source.GetHbitmap();

                    bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, System.Windows.Int32Rect.Empty,

                    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                    DeleteObject(ip);
                    
                    return bs;
                });

        }
        public static BitmapSource LoadBitmap(System.Drawing.Bitmap source)
        {
            
                ip = source.GetHbitmap();

                bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, System.Windows.Int32Rect.Empty,

                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                DeleteObject(ip);

                return bs;

        }

Async methods are written my me, and the other ones are from library.

And when i start program with async methods my imagebox stay grey, in debuger all parameters have error. So the question is why? :> 

解决方案

You say the UI is very slowly running....

And what method are you using?

Please use the 1st defined method instead, this is an Async method, which won't crash your UI;)


这篇关于任务,等待网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆