首页 > 其他 > 详细

OpenCV高斯模型

时间:2015-11-29 23:06:57      阅读:278      评论:0      收藏:0      [点我收藏+]
int main(int argc, char** argv)  
{  
    //std::string videoFile = "E:\\C_VC_code\\Text_Photo\\dingdang.avi";  
  
    //cv::VideoCapture capture;  
    //capture.open(videoFile);  
    //VideoCapture capture("E:\\C_VC_code\\Text_Photo\\大屏互动+行人检测_标清.flv");
    VideoCapture capture(0);
    if (!capture.isOpened())  
    {  
        std::cout<<"read video failure"<<std::endl;  
        return -1;  
    }  
  
  
    cv::BackgroundSubtractorMOG2 mog;  
  
    cv::Mat foreground;  
    cv::Mat background;  
  
    cv::Mat frame;  
    Mat frame1;
    long frameNo = 0;  
    double scalar = 0.3;

    while (1)  
    {  

        capture>>frame1;
        resize(frame1,frame,Size(frame1.cols*scalar,frame1.rows*scalar),1,1,3);
  
        // 运动前景检测,并更新背景  
        mog(frame, foreground, 0.2);         
          
        // 腐蚀  
        cv::erode(foreground, foreground, cv::Mat());  
        
        // 膨胀  
        cv::dilate(foreground, foreground, cv::Mat());  
  
        mog.getBackgroundImage(background);   // 返回当前背景图像  
        
        threshold(foreground,foreground,40,250,CV_THRESH_BINARY_INV);
        cv::imshow("foreground", foreground);  
        cv::imshow("background", background); 
  
        if (cv::waitKey(40) > 0)  
        {  
            break;  
        }  
    }  
     
    return 0;  
}  

 

OpenCV高斯模型

原文:http://www.cnblogs.com/mypsq/p/5005670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!