BackgroundSubtractorMOG2的apply(frame, mask) 求大神指导
opencv吧
全部回复
仅看楼主
level 2
iqpkfred 楼主
#include<opencv2\opencv.hpp>
#include "opencv2/core/core.hpp"
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
using namespace cv;
int main()
{
string videoFile = "4.avi";
VideoCapture capture;
capture.open(videoFile);
if (!capture.isOpened())
{
cout << "read video failure" << std::endl;
return -1;
}
BackgroundSubtractorMOG2* mog = createBackgroundSubtractorMOG2();
Mat foreground;
Mat background;
Mat frame;
long frameNo = 0;
while (capture.read(frame))
{
mog->apply(frame, foreground);
mog->getBackgroundImage(background); // 返回当前背景图像
imshow("video", foreground);
imshow("background", background);
system("pause");
if (waitKey(25) > 0)
{
break;
}
}
return 0;
}
2015年04月14日 16点04分 1
level 2
iqpkfred 楼主
执行到这句话,就over了,原因不明 mog->apply(frame, foreground);[泪]
2015年04月14日 16点04分 2
清除解决方案,重新编译。
2016年01月15日 02点01分
level 7
楼主,,你后来解决了这个问题没?我今天遇到了同样的问题
2015年07月29日 07点07分 4
level 6
你从哪里抄来的程序代码??BackgroundSubtractorMOG2这个是什么类型的?在哪里声明了?
2015年08月10日 05点08分 5
level 6
#include <stdexcept>
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/nonfree/gpu.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include <opencv2/video/background_segm.hpp>
#include"opencv/cv.h"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"#include"QDebug"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#ifdef _EiC
#define WIN32
#endif
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{ std::string videoFile = "../test/4.avi";
cv::VideoCapture capture; capture.open(videoFile);
if (!capture.isOpened())
{ std::cout<<"read video failure"<<std::endl; return -1; }
//cv::BackgroundSubtractorMOG2 mog;
cv::BackgroundSubtractorMOG2 mog;
cv::Mat foreground;
cv::Mat background;
cv::Mat frame;
long frameNo = 0;
while (capture.read(frame)) { ++frameNo;
std::cout<<frameNo<<std::endl;
// 运动前景检测,并更新背景
mog(frame, foreground, 0.001);
// 腐蚀 cv::erode(foreground, foreground, cv::Mat());
// 膨胀 cv::dilate(foreground, foreground, cv::Mat());
mog.getBackgroundImage(background); // 返回当前背景图像
cv::imshow("video", foreground);
cv::imshow("background", background);
if (cv::waitKey(25) > 0) {
break; } }
return 0;}
2015年08月10日 06点08分 6
level 6
我这个没有提示那样问题呢 只不过打不开视频怎么回事?
2015年08月10日 06点08分 7
level 1
打开文件需要自己的。。。
2016年01月06日 02点01分 8
level 1
碰到相同问题
2016年01月19日 09点01分 9
level 2
一模一样的问题,请问楼主解决了么
2016年08月20日 12点08分 10
1