Correct way to use accumulator (SOLVED) [closed]
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.