opencv3.2中BackgroundSubtractorMOG2算法

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);
    求大神帮忙解决一下