Ask Your Question
0

Can we do background subtraction MOG without shadow of the person ? [closed]

asked 2016-12-19 03:02:30 -0600

Allison gravatar image

updated 2016-12-19 04:12:38 -0600

berak gravatar image

With background subtraction MOG2 we get the shadow along but i want to use background subtraction MOG without shadow.The shadow of the person is being shown but i do not want to have the shadow at all.

When I'm using background subtraction MOG,the background substractor for MOG is not being recognised in opencv 3.1.

pMOG= new BackgroundSubtractorMOG();

int main(int argc, const char** argv)
{

    // Init background substractor
    Ptr<BackgroundSubtractor> pMOG = createBackgroundSubtractorMOG2().dynamicCast<BackgroundSubtractor>();

    // Create empy input img, foreground and background image and foreground mask.
    Mat img, foregroundMask, backgroundImage, foregroundImg;

    // capture video 
    VideoCapture cap("C:/Users/Videos/video.mp4");

    // main loop to grab sequence
    for (;;) {

        bool ok = cap.grab();

        if (ok == false) {

            cout << "Video File Not Found!" << std::endl;


        }
        else {

            // obtain input image from source
            cap.retrieve(img, CV_CAP_OPENNI_BGR_IMAGE);
            // Just resize input image if you want
            resize(img, img, Size(640, 480));

            // create foreground mask of proper size
            if (foregroundMask.empty()) {
                foregroundMask.create(img.size(), img.type());
            }

            // compute foreground mask 8 bit image
            // -1 is parameter that chose automatically your learning rate

            pMOG->apply(img, foregroundMask, true ? -1 : 0);

            // smooth the mask to reduce noise in image
            GaussianBlur(foregroundMask, foregroundMask, Size(11, 11), 3.5, 3.5);

            // threshold mask to saturate at black and white values
            threshold(foregroundMask, foregroundMask, 10, 255, THRESH_BINARY);

                // create black foreground image
                foregroundImg = Scalar::all(0);
            // Copy source image to foreground image only in area with white mask
            img.copyTo(foregroundImg, foregroundMask);

            //Get background image
            pMOG->getBackgroundImage(backgroundImage);

            // Show the results
            imshow("foreground mask", foregroundMask);
            imshow("foreground image", foregroundImg);

            //save the results
            imwrite("Result.jpg", foregroundMask);

            int key6 = waitKey(40);

            if (!backgroundImage.empty()) {

                imshow("still background image", backgroundImage);
                int key5 = waitKey(40);

            }


        }

    }

    return 0;
}
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by Allison
close date 2016-12-24 01:22:12.951953

Comments

I have been able to remove shadow but now the current problem is in detecting the moving objects in a static background as there is too much black colour overcoming on the objects.Only one part is being detected(is being shown in white colour and the other in black colour ) How to reduce those black colour on the objects? Is it because of lighting?

Allison gravatar imageAllison ( 2016-12-24 01:26:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-12-19 03:11:55 -0600

berak gravatar image

BackgroundSubtractorMOG was moved to https://github.com/opencv/opencv_contrib.

but you might try to disable the shadow detection

pMOG->setDetectShadows(false);
edit flag offensive delete link more

Comments

Actually he needs to set that to true, because he actually wants shadows removed. By default it is disabled because it slows down the algorithm!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-12-20 09:04:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-19 03:02:30 -0600

Seen: 1,109 times

Last updated: Dec 19 '16