Slitscan problem

I’ve been trying to learn to use openFrameworks by porting over previous work executed using with Processing.

I’ve dug out a slitscanning progam which utilised:

webcamSource.crop(camWidth/2, 0, 1, camHeight);

which was a pretty neat way to grab a central column of pixels from a webcam.

I can’t seem to find anything so straightforward as image.crop in the oF documentation - am I missing something?

There’s a method in ofImage:

void get(const ofImage& mom, unsigned int x, unsigned int y, unsigned int w, unsigned int h);  

Which you could use like this:

ofImage webcamImage;  
... // copy webcam capture into webcamImage  
ofImage croppedImage(1, camHeight);  
croppedImage.get(webcamImage, camWidth/2, 0, 1, camHeight);  

I’m guessing the reason OF has a get() instead of a crop() is that it’s more efficient to copy a subset of one image into a smaller image repeatedly than it is to continually reallocate the same image, so OF encourages the more efficient usage.

Thank you very much for your help.

I don’t quite get how to implement your advice - I get a

‘class ofImage’ has no member named ‘get’ message

and I’m not too sure how to get around it.

hi babel,
this example of slitscanning is definitely worth looking at, might give you some ideas… its very well optimised as well.

think a better way, although a more hands on method is to access the pixel data directly.
unsigned char * webcamPixels = webcamSource.getPixels();
you can then go through the pixel data row by row and add those rows of pixels to a ofTexture which will be your final output.


I recommend checking out that project too. It uses rows instead of columns, which can be more easily optimized (and results in a higher resolution if you’re just compiling lines over a very long/wide image). You’d just need to turn your camera on its side :slight_smile:

ofImage definitely has get(), you just have to call it with the right arguments. See libs/openFrameworks/graphics/ofImage.h for the method definition (which is just what I posted above). If you’re calling it with the right arguments, and still getting an error… I’m not sure. The getPixels() will be faster in the end, anyway.

Thanks for the help guys, much appreciated. I’ll follow your advice and give getPixels a go!

I’ve managed to get my slitscanner working but I have something very odd happening when I try to generate an image that is larger than the screen view of my MacBookPro.

In main.cpp I have:

ofSetupOpenGL(&window, 2400,900, OF_FULLSCREEN);

When I run my application all the pixels off screen to the right are rendered as black when I use:

img.grabScreen(0,0,camWidth*2,camHeight); // grab image
img.saveImage(fileName); // save

If in main.cpp I use:

ofSetupOpenGL(&window, 2400,900, OF_WINDOW);

I get all the pixels off the bottom of my screen rendered as black.

Any ideas please as to how I can avoid this happening?