ofxCvGrayscaleImage = ofxCvFloatImage broken in 006?

I’m not sure if I’m just doing something wrong or setting a grayscale cv image to a float cv image is broken. I’ve just ported code over to 006 and using the same code, just won’t work for copying the image.

 //Dynamic background with learn rate  
       fiLearn.addWeighted( img, fLearnRate);   
       grayBg = fiLearn; //doesn't work, returns black image  
   //recapature the background until image/camera is fully exposed  
   if((ofGetElapsedTimeMillis() - exposureStartTime) < CAMERA_EXPOSURE_TIME)      
        bLearnBakground = true;  
   //Capture full background  
   if (bLearnBakground == true){  
       fiLearn = img; //works  
       grayBg = fiLearn; //doesn't work, returns black image  
       bLearnBakground = false;  
   //This doesn't work either (grayBg = black image???)  
   //cvConvert(fiLearn.getCvImage(), grayBg.getCvImage());  
   //This isn't right since grayBG is always black  
   img.absDiff(grayBg, img); //Background Subtraction  

I’ve draw the fiLearn float image to screen and it’s correct (not black), but when I set the grayBg equal to it or try to cvConvert, the resulting grayBg always turns out black. This wasn’t an issue prior to 006.

Any help is appreciated.

Ok I still couldn’t figure this out…

I finally tried settings a ofxCvGrayscaleImage = ofxCvFloatImage by doing:

grayBg.setFromPixels(fiLearn.getPixels(), grayBg.width, grayBg.height);  

I couldn’t get the = opperator, cvConvert or anything else to work.

I noticed also there’s no a ofxCvShortImage and was wondering if that’s faster/better to use than ofxFloatImage.

Hey seth, if I hadn’t been traveling I had answered this earlier. Anyways, I found the same bug a few weeks ago when I moved ofxTouch to 006. The quick fix is to set the default range of the float image to 0-255: floatImg.setNativeScale(0,255)

The deeper issue is that float images have a default rang of 0-1 while grayscale images go from 0-255. In previous version of ofxOpenCv we had a wild mixture of presumed ranges for the float image depending which method you were using.

The conversion seems to be buggy when dealing with different ranges. The general behavior for the assignment operator should definitely be that 100% range gets mapped to 100% range no matter if actual range differs.

I probably have the fixes in the svn this weekend. I will also get the missing assignment operators for the shortImage in.

yep, I would definitely suggest using the new short image over the float image. It’s quite a bit faster.

As I said the assingment operators for the short image type is not in yet (going in the svn soon and probably part of v0061) but you can use the following code instead if you feel so inclined:

        //grayBgImg = shortBgImg;  // not yet implemented  
        cvConvertScale( shortBgImg.getCvImage(),   
                              255.0f/65535.0f, 0 );          

happy hacking,