1

我试图制作一个基于openCV的程序,它提取视频中的背景,我的问题是该程序将强度(光)的微小变化作为整个背景的变化,这是我基于它编写的代码OpenCV 样本,

   #include "opencv2/core/core.hpp"
   #include "opencv2/imgproc/imgproc.hpp"
   #include "opencv2/video/background_segm.hpp"
   #include "opencv2/highgui/highgui.hpp"
   #include <opencv2\calib3d\calib3d.hpp>
   #include <iostream>


int main(int argc, const char** argv){
 cv::VideoCapture cap(0);
cv::BackgroundSubtractorMOG2 bg_model;
bg_model.history = 10000;
bg_model.bShadowDetection = false;
cv::Mat img, fgmask,fgimg,smooth;
bool update =true;
int key =0;

while(key !=27){
    cap >> img;
    cv::blur(img,smooth,cv::Size(20,10));
    //update the model 
    if(fgimg.empty())
        fgimg.create(img.size(),img.type());
    bg_model(smooth,fgmask,update ? -1 :0);
    fgimg = cv::Scalar::all(0);
    img.copyTo(fgimg,fgmask);


    cv::imshow("fgimg",fgimg);
    cv::imshow("fgmask",fgmask);
    cv::imshow("img",img);
    std::cout << bg_model.backgroundRatio << std::endl;
    if(key == 'x')
        update= !update;
    if( update){
            std::cout <<  "update on " <<std::endl;
        }
        else{
            std::cout << "update off "<<std::endl;
        }
    key = 0;
    key = cv::waitKey(10);
}
 }

有谁知道如何将程序的灵敏度降级为强度。

提前感谢您的帮助!

4

1 回答 1

3

nmixtures您可以通过更改和使用该方法的minArea值来玩转灵敏度bg_modelinitialize

如链接:http ://www710.univ-lyon1.fr/~eguillou/documentation/opencv2/classcv_1_1_background_subtractor_m_o_g2.html

于 2013-05-30T08:27:04.067 回答