How can I make openCV Backgroundsubtraction KNN algorithm last longer, tracking a foregound object which is not moving

拈花ヽ惹草 提交于 2019-12-10 16:53:22

问题


I am trying to substract this building brick. .

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.

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

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

(Image shows frame 62)

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: I tried playing around with the history Paramer of

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

But there is no difference between history = 500 or history = 500000


回答1:


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);
        }
    }
}


来源:https://stackoverflow.com/questions/33018856/how-can-i-make-opencv-backgroundsubtraction-knn-algorithm-last-longer-tracking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!