首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运动检测

运动检测
EN

Stack Overflow用户
提问于 2013-07-13 00:08:21
回答 2查看 21.3K关注 0票数 11

我真的无法理解这件事,所以我希望有人能帮我一把。

我正试图通过我的网络摄像头来检测C#中的运动。

到目前为止,我尝试了多个库(AForge Lib),但是失败了,因为我不知道如何使用它。

一开始,我只想比较当前帧的像素和最后一个像素,但结果证明它就像but **t :I

现在,我的摄像头运行一个事件"webcam_ImageCaptured“每次从网络摄像头的图片,这是像5-10 fps。

但是我找不到一种简单的方法来获得这两幅图像的区别,或者至少是一些正常工作的东西。

有没有人知道我如何能做到这一点相当简单(尽可能)?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-13 03:20:21

使用您提到的库来实现运动检测是非常简单的。下面是一个AForge (版本2.2.4)的示例。它工作在一个视频文件,但你可以很容易地使它适应网络摄像头事件。

约翰斯是对的,但我认为,与这些图书馆玩耍可以简化对基本图像处理的理解。

我的应用程序以120 fast的速度在一台带有SSD的快速机器上处理720 p视频,在我的开发笔记本上处理大约50 fast的视频。

代码语言:javascript
复制
public static void Main()
{    
    float motionLevel = 0F;
    System.Drawing.Bitmap bitmap = null;
    AForge.Vision.Motion.MotionDetector motionDetector = null;
    AForge.Video.FFMPEG.VideoFileReader reader = new AForge.Video.FFMPEG.VideoFileReader();    

    motionDetector = GetDefaultMotionDetector();

    reader.Open(@"C:\Temp.wmv");

    while (true)
    {
        bitmap = reader.ReadVideoFrame();
        if (bitmap == null) break;

        // motionLevel will indicate the amount of motion as a percentage.
        motionLevel = motionDetector.ProcessFrame(bitmap);

        // You can also access the detected motion blobs as follows:
        // ((AForge.Vision.Motion.BlobCountingObjectsProcessing) motionDetector.Processor).ObjectRectangles [i]...
    }

    reader.Close();
}

// Play around with this function to tweak results.
public static AForge.Vision.Motion.MotionDetector GetDefaultMotionDetector ()
{
    AForge.Vision.Motion.IMotionDetector detector = null;
    AForge.Vision.Motion.IMotionProcessing processor = null;
    AForge.Vision.Motion.MotionDetector motionDetector = null;

    //detector = new AForge.Vision.Motion.TwoFramesDifferenceDetector()
    //{
    //  DifferenceThreshold = 15,
    //  SuppressNoise = true
    //};

    //detector = new AForge.Vision.Motion.CustomFrameDifferenceDetector()
    //{
    //  DifferenceThreshold = 15,
    //  KeepObjectsEdges = true,
    //  SuppressNoise = true
    //};

    detector = new AForge.Vision.Motion.SimpleBackgroundModelingDetector()
    {
        DifferenceThreshold = 10,
        FramesPerBackgroundUpdate = 10,
        KeepObjectsEdges = true,
        MillisecondsPerBackgroundUpdate = 0,
        SuppressNoise = true
    };

    //processor = new AForge.Vision.Motion.GridMotionAreaProcessing()
    //{
    //  HighlightColor = System.Drawing.Color.Red,
    //  HighlightMotionGrid = true,
    //  GridWidth = 100,
    //  GridHeight = 100,
    //  MotionAmountToHighlight = 100F
    //};

    processor = new AForge.Vision.Motion.BlobCountingObjectsProcessing()
    {
        HighlightColor = System.Drawing.Color.Red,
        HighlightMotionRegions = true,
        MinObjectsHeight = 10,
        MinObjectsWidth = 10
    };

    motionDetector = new AForge.Vision.Motion.MotionDetector(detector, processor);

    return (motionDetector);
}
票数 12
EN

Stack Overflow用户

发布于 2013-07-13 00:20:33

运动检测是一个复杂的问题,需要大量的计算能力。

试着先限制你想要检测的东西。随着复杂性的增加:你想要检测是否存在运动吗?你想检测出多少运动吗?是否要检测图像的实际移动区域?

我想你只是想知道什么时候发生了变化:

  • 互相减去相邻帧
  • 计算所有像素差的所有平方和。
  • 除以像素数
  • 注意你的网络摄像头流的号码。它将有一定的地面噪音,并将显着上升时,什么东西移动。
  • 试着限制在一个特定的颜色通道,这可能会改善的东西。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17625712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档