openframeworks / ofBook

openFrameworks community book
705 stars 201 forks source link

adaptive background subtraction clarification in computer vision #251

Open david-sullivan opened 7 years ago

david-sullivan commented 7 years ago

the text says "The overloaded operators for ofxCvImage make such running averages straightforward." however this only seems true for ofxCvFloatImage. If the background image is a type of ofxGrayscaleImage (or any other than floatImage), the example will not work. my workaround, which may not be the best way, was:

`//convert grayImage and grayBg to ofxCvFloatImage versions, multiply then convert back to grayImage

    grayImageFloat = grayImage; //from ofxGrayscaleImage to ofxFloatImage
    grayBgFloat = grayBg;
    grayImageFloat *= 0.01;
    grayBgFloat *= 0.99;
    grayBgFloat += grayImageFloat;
    grayBg = grayBgFloat; // back to ofxGrayscaleImage`
jhrtn commented 4 years ago

I just ran into the same issue and your workaround helped me get through the last part of the chapter. It would be good to see a clarification in the docs what the best way to do this is