如何让OpenCV的Backgroundsubtraction KNN算法持续更长的时间,跟踪未移动foregound对象更长、算法、对象、时间

2023-09-11 06:25:04 作者:陈词滥调°

我想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);
        }
    }
}
 
精彩推荐