原文地址:http://www.codesoso.com/code/Motion_Detection.aspx
本文实现了在连续视频数据流中几种不同的运动检测算法,他们都是基于当前帧图像和前一帧图像的比较,程序使用了AForge.NET framework库。其中的示例代码支持下面几种视频格式:AVI文件、网路相机的JPEG和MJPEG,本地的采集设备(USB相机等)。
感兴趣区域的获得方法:
// create processing filters sequence FiltersSequence processingFilter = new FiltersSequence( ); processingFilter.Add( new Difference( backgroundFrame ) ); processingFilter.Add( new Threshold( 15 ) ); processingFilter.Add( new Opening( ) ); processingFilter.Add( new Edges( ) ); // apply the filter Bitmap tmp1 = processingFilter.Apply( currentFrame ); // extract red channel from the original image IFilter extrachChannel = new ExtractChannel( RGB.R ); Bitmap redChannel = extrachChannel.Apply( image ); // merge red channel with moving object borders Merge mergeFilter = new Merge( ); mergeFilter.OverlayImage = tmp1; Bitmap tmp2 = mergeFilter.Apply( redChannel ); // replace red channel in the original image ReplaceChannel replaceChannel = new ReplaceChannel( RGB.R ); replaceChannel.ChannelImage = tmp2; Bitmap tmp3 = replaceChannel.Apply( image );