zoukankan      html  css  js  c++  java
  • opencv 2.4.7 的混合高斯算法 BackgroundSubtractorMOG问题

    视频处理是对于前景的提取,混合高斯算法的调用是在cv空间域名中但是在opencv2.4.7中提示直接调用发生错误:

    提示cv中没有BackgroundSubtractorMOG这个成员;

    我在网上查了一下分析说:2.4.7 使用时无法检测到主页中的例子。在只有我又将头文件加上,发现只要加上:

    #include <cvaux.h>就可以调用BackgroundSubtractorMOG这个成员;

    附上代码:

     1 #include<cv.h>
     2 #include<highgui.h>
     3 #include <cvaux.h>
     4 
     5 int main()
     6 {
     7     //打开视频文件
     8     cv::VideoCapture capture("D:\1\1.mp4");
     9     //检查视频是否成功打开
    10     if(!capture.isOpened())
    11         return 0;
    12     //当前视频帧
    13     cv::Mat frame;
    14     //前景图像
    15     cv::Mat foreground;
    16     cv::namedWindow("Extracted f");
    17     //使用默认参数的Mixture of Gaussian对象
    18     cv::BackgroundSubtractorMOG mog;
    19     bool stop(false);
    20     //遍历每一帧
    21     while(!stop){
    22         //读取下一帧
    23         if(!capture.read(frame))
    24             break;
    25         //更新背景并返回前景
    26         mog(frame,foreground,0.01);
    27         //对图像取反
    28         cv::threshold(foreground, foreground, 128, 255, cv::THRESH_BINARY_INV);
    29         //显示前景
    30         cv::imshow("Extracted f",foreground);
    31         //引入延迟;月可以通过按键Esc结束视频
    32         if(cv::waitKey(10)>=0)
    33             stop = true;
    34     }
    35 }

    总结:还是将常用的头文件都写上,以免出现这种没必要的错误!!

    1. #include <cv.h>
    2. #include <cxcore.h>
    3. #include <highgui.h>
    4. #include <cvaux.h>
    5. #include <iostream>
    6. #include <string>
  • 相关阅读:
    nginx变量(日志log_format)
    nginx中间件
    social-auth-app-django集成第三方登录
    Django REST Framework限速
    django-redis
    Django REST Framework extensions
    django-rest-framework-jwt
    FromXml 支付回调 xml 转数组
    下个月此时
    PHP 暂停函数 sleep() 与 usleep() 的区别
  • 原文地址:https://www.cnblogs.com/linmengran/p/5930682.html
Copyright © 2011-2022 走看看