[UWP] [VB] [XAML]从MediaCapture获取当前帧 [英] [UWP][VB][XAML]Obtaining The Current Frame From A MediaCapture

查看:97
本文介绍了[UWP] [VB] [XAML]从MediaCapture获取当前帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MediaCapture& CaptureElement允许用户预览相机。我需要定期(每隔一秒左右)使用当前帧进行分析。我找不到任何类型的事件,所以我刚刚创建了一个DispatcherTimer(也许
不是最有效的解决方法,但现在已经足够了)。我可能需要框架作为ImageSource和SoftwareBitmap(我将尝试在图像中找到彩色方块)。定期从
a MediaCapture获取当前帧的最佳方法是什么?谢谢。



Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

< blockquote>


>>定期从MediaCapture获取当前帧的最佳方法是什么?


这取决于您的需求,来自
此文档

DispatcherTimer
可用于在生成的同一线程上运行代码UI线程。在此线程上运行的代码有权创建和修改只能在UI线程上创建和修改的对象。这意味着如果您的所有业务在UI线程中都是
,那么这个类是一个很好的选择。


如果你没有对Tick处理程序中的UI线程做任何事情,只是需要一个计时器,你也可以使用

ThreadPoolTimer
。以下示例创建一个每60秒运行一次的工作项:

 TimeSpan period = TimeSpan.FromSeconds(60); 

ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source)=>
{
//
// TODO:工作
//

//
//使用UI核心调度程序更新UI线程。
//
等待Dispatcher.RunAsync(CoreDispatcherPriority.High,
() =>
{
//
//可以在此范围内访问UI组件。
//
});
},句号) ;

有关详细信息,请参阅:
创建定期工作项


问候,


斯坦利


I am using MediaCapture & CaptureElement to allow the user to preview the camera. I need to periodically (every second or so) use the current frame for analysis. I could not find any kind of event to do this, so I just created a DispatcherTimer (maybe not the most efficient workaround, but good enough for now). I will probably need the frame as an ImageSource and SoftwareBitmap (I will be attempting to find colored squares in the image). What is the best way to periodically obtain the current frame from a MediaCapture? Thanks.


Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Hi,

>> What is the best way to periodically obtain the current frame from a MediaCapture?

It depends on your needs, from this document, The DispatcherTimer can be used to run code on the same thread that produces the UI thread. Code running on this thread has the privilege to create and modify objects that can only be created and modified on the UI thread. That means if all your business is in UI thread, this class is a good choose.

If you aren't doing anything with the UI thread in your Tick handlers and just need a timer, you could also use ThreadPoolTimer instead. The following example creates a work item that runs once every 60 seconds:

    TimeSpan period = TimeSpan.FromSeconds(60);

    ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async (source) =>
    {
        //
        // TODO: Work
        //

        //
        // Update the UI thread by using the UI core dispatcher.
        //
        await Dispatcher.RunAsync(CoreDispatcherPriority.High,
              () =>
              {
                  //
                  // UI components can be accessed within this scope.
                  //
              });
    }, period);

For more details, please refer to: Create a periodic work item

Regards,

Stanly


这篇关于[UWP] [VB] [XAML]从MediaCapture获取当前帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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