assignment operator bug in ofxCv

This is a relatively minor bug which affects an assignment operators in ofxCvGrayscaleImage.

In the following the cvConvertScale line is wrong:

  
  
void ofxCvGrayscaleImage::operator =	( ofxCvFloatImage& mom ) {  
	if( mom.width == width && mom.height == height ) {  
		cvConvertScale( mom.getCvImage(), cvImage, 1.0f/255.0f, 0);  
	} else {  
        cout << "error in =, images are different sizes" << endl;  
	}  
}  
  

it should be:

  
  
cvConvertScale( mom.getCvImage(), cvImage, 1.0f, 0);  
  

or for brevity ( and I also read speed optimization) simply:

  
  
cvConvert( mom.getCvImage(), cvImage );  
  

We also might want to change addWeighted to:

  
  
void ofxCvFloatImage::addWeighted( ofxCvGrayscaleImage& mom, float f ) {  
	if( mom.width == width && mom.height == height ) {  
         IplImage* cvTemp = cvCreateImage( cvSize(width,height), IPL_DEPTH_32F, 1 );  
         //cvConvertScale( mom.getCvImage(), cvTemp, 1, 0 );  
         cvConvert( mom.getCvImage(), cvTemp );  
         cvAddWeighted( cvTemp, f, cvImage, 1.0f-f,0, cvImageTemp );  
         swapTemp();  
         cvReleaseImage( &cvTemp );  
    } else {  
        cout << "error in addWeighted, images are different sizes" << endl;  
    }  
}  
  

And ofxCvFloatImage::getPixels should probably also use cvConvert instead of cvConvertScale.

Thanks for the fix stefanix.

Putting cvConvert( mom.getCvImage(), cvTemp ); in the addWeighted function didn’t work for me though. The one in ofxCvGrayscaleImage did though.

hey cerupcat, can you elaborate.
I am about to commit these bugfixes to the svn.

We can use the the long version:
cvConvertScale( mom.getCvImage(), cvImage, 1.0f, 0);

but using the short version should be more cpu efficient.

I wonder how is cvConvert(…) not working for you. Does is compile at all?

/stefan