Ask Your Question

Revision history [back]

I have modify example samples\cpp\bgfg_segm.cpp and i have got an exception :

OpenCV Error: Assertion failed (frameType == CV_8UC1 || frameType == CV_8UC3) in cv::BackgroundSubtractorMOG2Impl::ocl_getBackgroundImage, file ......\modules \video\src\bgfg_gaussmix2.cpp, line 796

Ptr<BackgroundSubtractor> bg_model =
        createBackgroundSubtractorMOG2().dynamicCast<BackgroundSubtractor>();

Mat img0, img, fgmask, fgimg;
for(;;)
{
    cap >> img0;

    if( img0.empty() )
        break;

    resize(img0, img, Size(640, 640*img0.rows/img0.cols), INTER_LINEAR);

    if( fgimg.empty() )
      fgimg.create(img.size(), img.type());
    Mat imgf(img.rows, img.cols, CV_32FC1);
    for (int i = 0; i< img0.rows; i++)
    for (int j = 0; j < img0.cols; j++)
        imgf.at<float>(i, j) = img.at<Vec3b>(i, j)[0];
        //update the model
    bg_model->apply(imgf, fgmask, update_bg_model ? -1 : 0);
    if( smoothMask )
    {
        GaussianBlur(fgmask, fgmask, Size(11, 11), 3.5, 3.5);
        threshold(fgmask, fgmask, 10, 255, THRESH_BINARY);
    }

    fgimg = Scalar::all(0);
    img.copyTo(fgimg, fgmask);

    Mat bgimg;
    bg_model->getBackgroundImage(bgimg);

    imshow("image", img);
    imshow("foreground mask", fgmask);
    imshow("foreground image", fgimg);
    if(!bgimg.empty())
      imshow("mean background image", bgimg );

    char k = (char)waitKey(30);
    if( k == 27 ) break;
    if( k == ' ' )
    {
        update_bg_model = !update_bg_model;
        if(update_bg_model)
            printf("Background update is on\n");
        else
            printf("Background update is off\n");
    }
}

I have modify example samples\cpp\bgfg_segm.cpp and i have got an exception :

OpenCV Error: Assertion failed (frameType == CV_8UC1 || frameType == CV_8UC3) in cv::BackgroundSubtractorMOG2Impl::ocl_getBackgroundImage, file ......\modules \video\src\bgfg_gaussmix2.cpp, line 796796 In a post I have seen that some assertion are not print when you are in release mode.

Ptr<BackgroundSubtractor> bg_model =
        createBackgroundSubtractorMOG2().dynamicCast<BackgroundSubtractor>();

Mat img0, img, fgmask, fgimg;
for(;;)
{
    cap >> img0;

    if( img0.empty() )
        break;

    resize(img0, img, Size(640, 640*img0.rows/img0.cols), INTER_LINEAR);

    if( fgimg.empty() )
      fgimg.create(img.size(), img.type());
    Mat imgf(img.rows, img.cols, CV_32FC1);
    for (int i = 0; i< img0.rows; i++)
    for (int j = 0; j < img0.cols; j++)
        imgf.at<float>(i, j) = img.at<Vec3b>(i, j)[0];
        //update the model
    bg_model->apply(imgf, fgmask, update_bg_model ? -1 : 0);
    if( smoothMask )
    {
        GaussianBlur(fgmask, fgmask, Size(11, 11), 3.5, 3.5);
        threshold(fgmask, fgmask, 10, 255, THRESH_BINARY);
    }

    fgimg = Scalar::all(0);
    img.copyTo(fgimg, fgmask);

    Mat bgimg;
    bg_model->getBackgroundImage(bgimg);

    imshow("image", img);
    imshow("foreground mask", fgmask);
    imshow("foreground image", fgimg);
    if(!bgimg.empty())
      imshow("mean background image", bgimg );

    char k = (char)waitKey(30);
    if( k == 27 ) break;
    if( k == ' ' )
    {
        update_bg_model = !update_bg_model;
        if(update_bg_model)
            printf("Background update is on\n");
        else
            printf("Background update is off\n");
    }
}