如何使用 AForge 设置运动检测?
我正在尝试使用 AForge.NET 框架设置运动检测。我正在使用此页面上提供的信息。
我已经设置了一个 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");
}
}
当选择视频流时,探测器
被初始化为私有类变量。
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);
}
i'm trying to setup motiondetection using the AForge.NET framework. I'm using the information provided on this page.
I've setup a DirectShow videostream which feeds a part of my desktop through a stream. I can choose this stream in the sample videoplayer project which is provided with AForge. (And I see my desktop through the player).
However, when I run the code below I receive a NullReferenceException. What am I missing?
// 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");
}
}
The detector
is initialized as private class variable when a videostream is chosen.
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 BlobCountingObjectsProcessingmotionProcessor,似乎您已声明该变量两次,一次未初始化,一次初始化。
一种是外部方法作用域,另一种是内部方法作用域。
我认为这就是您的 NullReferenceException 的来源。
Have a look at the
BlobCountingObjectsProcessing motionProcessor
, it seems you've declared the variable twice, once not initialized and once initialized.One outside method scope and one inside method scope.
I think that's where your NullReferenceException is coming from.