跟踪未移动foregound对象

跟踪未移动foregound对象

本文介绍了如何让OpenCV的Backgroundsubtraction KNN算法持续更长的时间,跟踪未移动foregound对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想substract此建筑用砖。

I am trying to substract this building brick..

有关,我利用OpenCV中3.0规定的KNN算法。要初始化我使用40帧无砖背景模型。

For that I am using the KNN algorithm provided by opencv 3.0.To initialize the background model I am using 40 frames without the brick.

总之它的工作原理pretty的好。(砖影)

All in all it works pretty well.(Brick with Shadow)

唯一的问题是,该算法开始松动的砖周围框架58

The only problem is that the algorithm starts loosing the brick around Frame 58

(图像显示帧62)

框64后,我得到的只有黑色图像。我知道这不会发生,如果砖将移动,但不幸的是也有很长的序列它不`吨。

After frame 64 I get only black images. I know this wouldn't happen if the brick would move, but unfortunatly there are long sequences where it doesn`t.

是否有人知道解决这个?

Does somebody know a solution to this?

PS:我试图与历史Paramer玩弄

PS: I tried playing around with the history Paramer of

cv::createBackgroundSubtractorKNN(int history,double Threshold, bool detectShadows= true)

但是,在历史= 500或历史= 500000

推荐答案

一个容易的,但速度慢的解决办法是重新初始化背景模型每五帧。

A easy but slow solution is to reinitialize the background model every five frames.

for (size_t i = 0; i < imageList.size(); i++){
    if (i % 5 == 0){
        for (auto& it : backgroundList){

            string nextFrameFilename(it.string());
            frame = cv::imread(nextFrameFilename);
            pMOG->apply(frame, fgMaskMOG2);
            imshow("Frame", frame);
            imshow("FG Mask MOG 2", fgMaskMOG2);
            keyboard = cv::waitKey(30);
        }
    }
}

这篇关于如何让OpenCV的Backgroundsubtraction KNN算法持续更长的时间,跟踪未移动foregound对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:17