【问题标题】:How to feed frames into motion detector object AForge.net?如何将帧输入运动检测器对象 AForge.net?
【发布时间】:2017-08-03 11:16:39
【问题描述】:

我正在尝试使用 AForge.net 框架制作一个简单的运动检测程序。在 AForge 网站上有一个这样的程序的例子,但它很模糊:

    // create motion detector
MotionDetector detector = new MotionDetector(
    new SimpleBackgroundModelingDetector( ),
    new MotionAreaHighlighting( ) );

// continuously feed video frames to motion detector
while ( ... )
{
    // process new video frame and check motion level
    if ( detector.ProcessFrame( videoFrame ) > 0.02 )
    {
        // ring alarm or do something else
    }
}

我需要一些有关 while 循环条件的帮助,因为我找不到如何将视频帧输入 MotionDetector 对象的解决方案。

谢谢。

【问题讨论】:

    标签: c# aforge motion-detection


    【解决方案1】:

    您需要利用 AForge 的 DirectShow VideoInputDevice。而不是一个while循环,你将有一个NewFrame事件来控制运动检测器。

    首先你需要参考资料:

    using AForge.Video.DirectShow;
    using AForge.Video;
    using AForge.Vision.Motion;
    using System.Drawing;
    

    接下来,您将需要获取您的捕获设备,例如您的网络摄像头并为设备的 NewFrame 事件添加一个新的帧事件处理程序:

    Cameras = new FilterInfoCollection(FilterCategory.VideoInputDevice);
    VideoCaptureDevice Camera = new VideoCaptureDevice(Cameras[0].MonikerString);
    Camera.NewFrame += new NewFrameEventHandler(ProcessNewFrame);
    

    现在您可以根据自己的选择实现 NewFrameEventHandler:

    private void ProcessNewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        Bitmap frame = (Bitmap) eventArgs.Frame.Clone();
        if (detector.ProcessFrame(frame) > 0.02)
        {
            // ring alarm or do somethng else
        }
    }
    

    【讨论】:

    • 如果您需要更多帮助,请告诉我。我自己刚刚完成了一个基于 AForge 的运动跟踪器项目。
    猜你喜欢
    • 2011-10-26
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多