Hi, I’m trying to crop the image captured from my firewire camera but I can’t get it working.

I’ve searched the forum but didn’t find anything that worked for me.

I found this:…-light=crop

but I can’t get the Ipllmage class to work and I didn’t find anywahere that shows how to work with this class.

I tried to do a cropping function myself, but it doen’st work:

void crop(unsigned char *img1, unsigned char *img2, int x0, int y0, int w, int h){  
	int x, y, i;  
	ofImage aux;  
	unsigned char* newImg;  
	aux.allocate(w, h, OF_IMAGE_GRAYSCALE);  
	newImg  = new unsigned char[w*h];  
	for(x=x0; x<w; x++){  
		for(y=y0; y<h; y++){  
			i = y*320 + x;  
			newImg[i] = img1[i];  
	aux.setFromPixels(newImg, w, h,  OF_IMAGE_GRAYSCALE);  
	aux.resize(320, 240);  
	img2 = aux.getPixels();  

Can Anyone help me ?

Is there a tutorial or guide for cropping ?

It is a very simple and basic feature in Processing an Max/MSP/Jitter , it shouldn’t be that hard to get it working with OF


Zach posted some code for cropping here:…-light=crop

You can also do ROI approach on the video and then allocate a new image the same size as the ROI. Then you can set the croppedImage = ROIimage.

On firewire cameras you should avoid cropping by sw, instead do it by hw using the driver of the SDK of the camera. As a bonus you will get:

  1. Higher FPS from the camera which is very sweet.
  2. Less CPU overload (a tiny amount)

For me, that’s the way to go, anything you can do to get higher FPS is worth the time.

Thanks for the help.

I’m using unibrain Fire-i camera on Mac OSX, but the driver doesn’t have a cropping funcionality.

So I’ll have to go with an OF algorithm for cropping.

The ROI seems good but I couldn’t figure out how to work with the Ipllmage class, I’ll google it some more.

But anyway, my code should work, but then I found that there’s a bug with setFromPixels() method when used with grayscale images, maybe that’s the problem.
It is very similar to Zachs code.

Thansk for the help.