如何设置运动检测使用AForge?
-
20-09-2019 - |
题
我使用AForge.NET框架试图安装motiondetection。我使用提供此页面的信息。
我设置一个DirectShow视频流,它通过流进我的桌面的一部分。我可以选择在设置有AForge样品录像机项目此流。 (我也看到我的桌面通过播放器)。
然而,当我运行代码下面我收到NullReferenceException。我缺少什么?
// New frame received by the player
private void videoSourcePlayer_NewFrame( object sender, ref Bitmap image )
{
if (this.detector.ProcessFrame(image) > 0.02)
{
Console.WriteLine("Motion");
}
else
{
Console.WriteLine("No motion");
}
}
在detector
被初始化为当选择了视频流私有类变量。
private MotionDetector detector;
private BlobCountingObjectsProcessing motionProcessor;
// Open video source
private void OpenVideoSource( IVideoSource source )
{
BlobCountingObjectsProcessing motionProcessor = new BlobCountingObjectsProcessing();
MotionDetector detector = new MotionDetector(
new SimpleBackgroundModelingDetector(),
motionProcessor);
}
解决方案
有一个看看BlobCountingObjectsProcessing motionProcessor
,看来你已经声明的变量两次,一次没有初始化,初始化一次。
一个外方法范围和一个内部方法的范围。
我想这就是你的NullReferenceException的来源。
不隶属于 StackOverflow