使用opencv仅检测缓慢移动的物体
detecting only slow moving objects using opencv
我使用OpenCV进行运动检测,并为此使用后台减法算法。我从网上得到了以下代码。
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
cv::VideoCapture cap(0);
bg.nmixtures = 3;
bg.bShadowDetection = false;
const int history = 5;
cv::BackgroundSubtractorMOG2 bg (history,nmixtures,bShadowDetection);
std::vector<std::vector<cv::Point> > contours;
cv::namedWindow("Frame");
cv::namedWindow("Background");
for(;;)
{
cap >> frame;
bg.operator ()(frame,fore);
bg.getBackgroundImage(back);
cv::erode(fore,fore,cv::Mat());
cv::dilate(fore,fore,cv::Mat());
cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
cv::imshow("Frame",frame);
cv::imshow("Background",back);
if(cv::waitKey(30) >= 0) break;
}
所以我可以设置一个阈值,这样如果新旧框架的变化超过阈值,就什么都不做了。或者可能是其他一些算法,应该适合我只捕捉缓慢移动物体的情况。
如果您希望检测慢速移动的对象,您可以更改高斯混合模型中的历史值(增加它)。
您可以尝试使用帧的移动平均值,而不是使用每一帧作为BG减法的输入。或者使用移动平均值来输出BG减法,然后通过阈值进行二值化。
请参阅addWeighted and moving Average(请参阅Cucumulative moving Average)。
整合将减少快速变化的影响。
相关文章:
- 将对象移动到std::shared_ptr
- 何时在引用或唯一指针上使用移动语义
- 如何从具有移动语义的类对象中生成共享指针
- 将shared_ptr移动到<StructA>shared_ptr<变体<结构A、结构 B>>
- C / C++ 移位/偏移/向左或向右移动位图?
- MSVC将仅移动结构参数解释为指针
- 自定义先决条件对移动分配运算符有效吗
- 返回值优化:显式移动还是隐式
- 当有分配器意识的容器被复制/移动时,反弹分配器是否被复制/移走
- 为什么复制而不是移动数据元素?
- 可以使用移动语义更改或改进此C++代码吗?
- 缓慢提升ASIO
- 使lambda不可复制/不可移动
- c++在使用指针时移动语义
- 将QGraphicsItem的移动区域限制在多边形区域内
- SendInput()鼠标移动计算
- 按值 C++ 返回时进行双倍移动
- 移动二维数组中的字符
- 如何在屏幕上缓慢移动对象
- 使用opencv仅检测缓慢移动的物体