Deleting unsigned char * ??

Hi, I have a feeling this could be really simple but I cant seem to figure out how to do it. I want to clear an unsigned char and reload it, because I have some blur code which is just building up and up, more and more blurred.

The current setup I have crashes:

  
  
  
void ofBlurImages::update(){  
  
 unsigned char * colorPixels;  
 colorPixels = sequenceBlockout[frame].getPixels();  
 superFastBlur(w, h, int(ofRandom(0,30)));  
 finalBluredImage.allocate(w, h, GL_RGB);  
 finalBluredImage.loadData(w, h,GL_RGB);  
 delete colorPixels;   
  
}  
  

Thanks, any help/comments/suggestions will be greatly appreciated.

Ian

there is a flaw with this:

unsigned char * colorPixels;
colorPixels = sequenceBlockout[frame].getPixels();
delete colorPixels;

a) the first line creates a pointer

b) the second line makes the pointer point to the same place in memory as the pixels array inside of the image (or video, etc).

c) the third line deletes the colorPixels, which essentially points to data inside of sequenceBlockout[], which, unless you really want to do that, likely will cause you problems when you go to use sequenceBlockout again, etc.

I don’t think you need the delete function in this case. if you were allocating data, such as:

  
unsigned char * colorPixels = new unsigned char[w*h];  

then it’d make sense to delete them… in this case, the data is allocated when you load a movie or image (or in the case of opencv image, when you call allocate), there is no reason to clear it and also, most objects have a clear function or a destructor which takes care of it for you.

hope that helps!
zach

Cool thanks for the quick reply Zach!

I wonder if I could set it up using 2 arrays of pixels, when its using one it clears the other, the problem I have is each frame it doesn’t seem to refresh itself, it doesn’t pull in the pixels from the image again, it just works from what it already got, so it just gets more and more blurred.

So if the first frame I tell it to be 10 pixels blurred and then the second I set it to be just 3, it ends up being 13! seems a bit weird doesn’t it.

Thanks again,

Ian

if you want to blur by a different amount each time through you’ll need to make sure you keep a copy of the original pixels. if superFastBlur() overwrites the source image then of course the blur is going to add up over time…

d

Yea it does, I just clicked, cool thanks Damian I was going to look into reloading but having an original image and a image to blur is a far better idea, cheers!

Ian