Ask Your Question

Used of BackgroundSubtractorMOG2::operator() in OpenCV-3.0.0

asked 2015-06-08 11:49:09 -0500

desri gravatar image


I need a clarification about the use of BackgroundSubtractorMOG2::operator() in OpenCV-3.0.0. What is the data type of the input image that this operatorworks on? Is is 32F or UINT8? When I used BackgroundSubtractorMOG::operator(), it required the input image to be UINT8. In BackgroundSubtractorMOG2::operator(), I sent the input image as 32F and it didn't give me an error. However, I was wondering if inside the code, it truncates a 32F data into UINT8. This worries me, as it would reduce the resolution of the image inside.

Your help is appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-06-08 15:09:31 -0500

LBerger gravatar image

updated 2015-06-09 01:12:25 -0500

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 In a post I have seen that some assertion are not print when you are in release mode.

Ptr<BackgroundSubtractor> bg_model =

Mat img0, img, fgmask, fgimg;
    cap >> img0;

    if( img0.empty() )

    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++)<float>(i, j) =<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;

    imshow("image", img);
    imshow("foreground mask", fgmask);
    imshow("foreground image", fgimg);
      imshow("mean background image", bgimg );

    char k = (char)waitKey(30);
    if( k == 27 ) break;
    if( k == ' ' )
        update_bg_model = !update_bg_model;
            printf("Background update is on\n");
            printf("Background update is off\n");
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-06-08 11:49:09 -0500

Seen: 573 times

Last updated: Jun 09 '15