Correct way to use accumulator (SOLVED) [closed]

asked 2014-04-17 15:10:48 -0600

Yan Foto gravatar image

updated 2014-04-17 15:21:42 -0600

I have been trying to create a foreground subtractor which accumulates a number of frames upon program starts and uses the generated image to detect foreground objects which may enter the view in a later time. However I am confused which image type I should use here in order to avoid "Assertion failed (func != 0) in accumulate" in one hand and end results with wrong colors on the other hand.

Code:

void Test::initBackgroundImage() {
    int totalCount = 3;
    int currentCount = 0;

    Mat camFrame;
    while(currentCount < totalCount) {
        cam >> camFrame;

        if(bgImg.empty()) {
            cam >> bgImg;
            bgImg.create(camFrame.size(), CV_32FC3);
        }

        accumulate(camFrame, bgImg);

        currentCount++;
    }
}

NOTE: Variables are all initialized in the constrcuctor.

Why does my code generate an image with wrong colors?

UPDATE:

I found out on this blog that adding the following line:

convertScaleAbs(bgImg, bgImg);

after the loop corrects the colors. Can someone please explain what exactly happens here?

UPDATE 2:

I just found out that the produced image has been correct. But since it was a 32 bit integer image, it was shown with different colors when calling imshow. See docs for more.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2014-04-18 04:08:33.185610