我真的无法理解这件事,所以我希望有人能帮我一把。
我正试图通过我的网络摄像头来检测C#中的运动。
到目前为止,我尝试了多个库(AForge Lib),但是失败了,因为我不知道如何使用它。
一开始,我只想比较当前帧的像素和最后一个像素,但结果证明它就像but **t :I
现在,我的摄像头运行一个事件"webcam_ImageCaptured“每次从网络摄像头的图片,这是像5-10 fps。
但是我找不到一种简单的方法来获得这两幅图像的区别,或者至少是一些正常工作的东西。
有没有人知道我如何能做到这一点相当简单(尽可能)?
发布于 2013-07-12 19:20:21
使用您提到的库来实现运动检测是非常简单的。下面是一个AForge (版本2.2.4)的示例。它工作在一个视频文件,但你可以很容易地使它适应网络摄像头事件。
约翰斯是对的,但我认为,与这些图书馆玩耍可以简化对基本图像处理的理解。
我的应用程序以120 fast的速度在一台带有SSD的快速机器上处理720 p视频,在我的开发笔记本上处理大约50 fast的视频。
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);
}
发布于 2013-07-12 16:20:33
运动检测是一个复杂的问题,需要大量的计算能力。
试着先限制你想要检测的东西。随着复杂性的增加:你想要检测是否存在运动吗?你想检测出多少运动吗?是否要检测图像的实际移动区域?
我想你只是想知道什么时候发生了变化:
https://stackoverflow.com/questions/17625712
复制相似问题