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, floatImage;
while(currentCount < totalCount) {
cam >> camFrame;
if(bgImg.empty()) {
cam >> bgImg;
bgImg.create(camFrame.size(), CV_32FC3);
}
camFrame.convertTo(floatImage, CV_32FC3);
accumulate(camFrame, bgImg);
currentCount++;
}
}
NOTE: Variables are all initialized in the constrcuctor.
is the conversion (to e.g. CV_32FC3
) at all necessary? Why does my code generate an image with wrong colors?