questions in GMM...
Can anybody figure out what's going on with the code? I am using opencv310
#include <opencv2\opencv.hpp>
#include <iostream>
#include <string>
using namespace cv;
int main(int argc, char** argv)
{
std::string videoFile = "1.avi";
VideoCapture capture;
capture.open(videoFile);
if (!capture.isOpened())
{
std::cout << "read video failure" << std::endl;
return -1;
}
Ptr<BackgroundSubtractorMOG2> subtractor;
cv::Mat foreground;
cv::Mat background;
cv::Mat frame;
long frameNo = 0;
while (capture.read(frame))
{
++frameNo;
std::cout << frameNo << std::endl;
// 运动前景检测,并更新背景
subtractor->apply(frame, foreground, 0.001);
// 腐蚀
cv::erode(foreground, foreground, cv::Mat());
// 膨胀
cv::dilate(foreground, foreground, cv::Mat());
cv::imshow("video", foreground);
cv::imshow("background", background);
if (cv::waitKey(25) > 0)
{
break;
}
}
return 0;
}
Well, you're never setting background to anything at all, ever. More importantly, what's not working?
-the background is in
cv::Mat background;