xigua061126
xigua061126
2018-12-10 07:45

opencv3.2中BackgroundSubtractorMOG2算法

  • opencv 3.2

BackgroundSubtractorMOG2算法中执行到这句话,就over了,原因不明 mog->apply(frame, foreground)图片说明

代码如下
int main()
{
cv::VideoCapture capture("walk.avi");
if (!capture.isOpened())
return 0;

// current video frame
cv::Mat frame;
// foreground binary image
cv::Mat foreground;
// background image
cv::Mat background;

cv::namedWindow("Extracted Foreground");

// The Mixture of Gaussian object
// used with all default parameters
cv::Ptr<cv::BackgroundSubtractorMOG2> ptrMOG = cv::createBackgroundSubtractorMOG2();
ptrMOG->setVarThreshold(120);
bool stop(false);
Mat fgimg;
// for all frames in video
while (!stop) {

    //capture >> frame;
    if (!capture.read(frame))
        break;
    cv::imshow("Extracted Foreground1", frame);
    // update the background
    // and return the foreground
    ptrMOG->apply(frame, foreground, 0.01);
    求大神帮忙解决一下
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐

换一换