下面这段代码利用OpenCV实现了最为简单的基于自适应背景更新的运动目标检测算法。
即:
运动前景提取——背景减除
foreground = |frame - background| > threshold
更新背景模型——滑动平均滤波
background = background + (frame - background) * alpha = background * (1 - alpha) + frame * alpha
//运动前景检测——基于自适应背景更新
//Author: www.icvpr.com
//Blog: http://blog.youkuaiyun.com/icvpr
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
int main(int argc, char** argv)
{
std::string videoFileName = "../test.avi";
int threshold = 25 ; // 二值化阈值
f

该博客介绍了如何运用OpenCV实现基于自适应背景更新的运动目标检测算法。通过背景减除与滑动平均滤波的方法,有效地提取运动前景,并更新背景模型。详细代码和相关资源可在www.icvpr.com找到。
最低0.47元/天 解锁文章
1031





