Image warping and Bg Learning with float images

Here are a few simple code examples I put together recently:

Image Warping

http://csugrue.com/code/?p=1

A simple application that demonstrates how to warp an image. This can be quite useful when colocating a video and projection.

Float Image Class / Background Learning

http://csugrue.com/code/?p=3

A simple app that demonstrates how to use a float image to slowly blend two images together. This can be a useful way to learn a background when performing computer vision.

Thanks for the examples Chris.

In background learning, I do the following…

  
  
// get colour image from movie clip  
colorImg.setFromPixels(testmovie.getPixels(), 320,240);  
  
// convert to greyscale  
grayImage.setFromColorImage(colorImg);  
  
// pass grey image to fiLearn  
fiLearn.addWeighted(grayImage, fLearnRate);  
  
// make the background be the float image  
grayBg = fiLearn;  
  

grayBG and grayImage are ofCvGrayscaleImage.

I get the following build error…

c:\openframeworks\v0.02\app\mycv\src\testapp.cpp(47) : error C2679: binary ‘=’ : no operator found which takes a right-hand operand of type ‘ofCvFloatImage’ (or there is no acceptable conversion)

c:\openframeworks\v0.02\libs\openframeworks\computervision\ofcvgrayscaleimage.h(40): could be ‘void ofCvGrayscaleImage::operator =(ofCvGrayscaleImage &)’
while trying to match the argument list ‘(ofCvGrayscaleImage, ofCvFloatImage)’
ofCvFloatImage.cpp

Any idea what I’m doing wrong?

Zach, will you be adding floatImage class to OFW 0.03? :slight_smile:

Hi Chris,

I made some changes to the ofCvGrayscaleImage class as well so you can copy between the float image and the grayscale image. It sounds like you might be missing the new functions.

in ofCvGrayscaleImage.h you need:
class ofCvFloatImage; // forward declaration at top

  
void operator =		( ofCvFloatImage & mom );  
  

and in ofCvGrayscaleImage.cpp

  
void ofCvGrayscaleImage::operator =	( ofCvFloatImage & mom ){  
	if (mom.width == width && mom.height == height){  
		cvConvertScale( mom.getCvImage(), cvImage, 1, 0 );  
	} else {  
		printf("error in =, images are different sizes\n");  
	}  
}  

Let me know if that solves the problem!

Hi Chris

I realised this not long after posting. Have replaced ofCvGrayscaleImage files with yours now.

However I still get a problem with the = operator.

grayBg = fiLearn;

That causes a problem:

1>Compiling…
1>testApp.cpp
1>Linking…
1>testApp.obj : error LNK2001: unresolved external symbol “public: void __thiscall ofCvGrayscaleImage::operator=(class ofCvFloatImage &)” (??4ofCvGrayscaleImage@@QAEXAAVofCvFloatImage@@@Z)
1>Release\openFrameworksApp.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at “file://c:\OpenFrameWorks\v0.02\app\myCV\obj\Release\BuildLog.htm”
1>openFrameworksApp - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Also, does fiLearn.draw(x,y) work for you? I just get a really distorted image beyond recognition.

chris

sorry, i finally had time to fix this… you are right - drawing totally doesn’t work. I updated the class so it converts to grayscale for the draw:

http://csugrue.com/codeArchive/openFram-…-loatImage/

not sure about the = error, but I added a new function so you can pass in a grayscale image to the float image object to set it:

  
myFloatImage.setGrayscaleImage(myGrayImage);  

Hi Chris

Thanks. I’m not sure you updated the online files though, the draw function is the same…

I fixed the other problem, hadn’t updated my grayscale class.

Thanks

yeah, you are right i uploaded an earlier version. thanks for catching that! they are fixed now. the change is in the getPixels function so it actually returns an unsigned char array. let me know if you encounter any other problems or want to add something to it

Hi Chris

Thanks, the Draw function now works.

Have you got setFromPixels working?

Here is some code that crashes it:

  
  
// .h declare  
unsigned char * myPixels;  
ofCvFloatImage floatImage;  
  
// .cpp setup  
floatImage.allocate(width, height);  
myPixels= new unsigned char[width*height];  
for(int i = 0; i < (width*height); i++){  
  myPixels[i] = 1.0;  
}  
  
// .cpp update  
floatImage.setFromPixels(myPixels, width, height);  
  

Any ideas whats going on here?
Maybe cvReleaseImage(&cvTempImage); in setFromPixels ?

Hi Chris

I was wondering if setFromPixels() worked for you?