Tag: OpenCV

More libcvfx: New effects and runs in Windows

March 29, 2008 » Geek

I got libcvfx compiled on Windows with Dev-C++. I don’t have it as a library or anything, just got the demo working for now, proof of concept if you will. It was a bit slower on Windows, and I didn’t get the 640×480 out of my web cam. Additionally the highgui didn’t register the arrow keys right so I had to change those.

What I was really wanting to see was if it would run in Windows at all. This would possibly open up a bigger range of web cams for the CameraBooth project, perhaps some of the higher end, higher resolution ones.

Anyway, here’s a screen of it running on Windows and one on Linux for good measure. Click through for the big images.



Additionally I’ve added a few new effects since the last post. Some don’t capture well, so I’ll just describe those ones.

Photo Copy
This one takes a threshold and any pixel under the threshold is turned black, any pixel over it is turned a user specified color, default is white. This tends to be harsh, it might be good to run a blur on it or maybe set a few midpoint values between black and the color to fuzz it a bit.

Cuts the image into as many strips as you want, then flips every other strip. Defaults to 4 strips.

This isn’t a new effect, but now you can choose which corners to exchange.

There are a number of effects I didn’t take pictures for.

VStripFlip is like HStripFlip except vertical.
Broken Television is a motion effect where the image scrolls like an out of sync TV. Hard to describe really.
Noise just injects pseudo-random pixels into the image, but it does a poor job of it right now.
Interlace Lines replaces every other horizontal line with all black.

I’ll have more about these effects as well as pictures and maybe video once I get a project page set up for libcvfx. For now you can hit up the repo for source, or grab the Window binary here. You will need the OpenCV libraries installed, and in your PATH.


March 10, 2008 » Geek

I’ve been playing with OpenCV recently and was having troubles with creating effects. That’s all over now thanks to the OpenCV mailing list, you can see the fix in the comments of this post. Since I can now manipulate colors and pixels with ease I’ve been writing a few more neat effects. And yes, I know that this is not what OpenCV is for, but it’s a really handy library and I like it.

I decided to pull them out of my test program and make them into a little library. Having never made a library before I[m sure I did some things wrong, but it works and that’s what I care about right now.

I doubt my manipulation method is the fastest, but I’ve tried to be economical and share resources between effects. I also included a test program so you can try out the filters. These are all written by me so far, with inspiration but no code from other sources. I’m hoping to port over some of effectv’s super cool filters as time goes on. You can click through on any of the pictures below for a 640×480 version.

This is my normal image I get from my cheap labtec webcam.
And yes, I am that good looking.

Probably the simplest effect, it just involves turning off the blue and red channels.

Copies and flips the left side onto the right.

Simple like green, just sums the three channels into one value.

This one swaps the top left and bottom right corners. I’m going to swap top right and bottom left later.

Horizontal Flip

Vertical Flip

This is one of the harder ones. It stores three frames in memory and then combines them with the current frame for a ghosting type of effect.

Oompa Loompa
For lack of a better name.


This is the only one with parameters, and one of my favorites.
The parameter is the “pixel size”.
From top down it is set at 2, 6 and 10.

You can grab the 0.01 source here (doesn’t have the invert filter) or browse the svn repo at http://svn.velvetcache.org/libcvfx/ for more current stuff.

Screwy OpenCV Manipulations

March 2, 2008 » Geek

I’ve been playing more with OpenCV and I think I’m missing something. I can’t do any manipulations on the image data without really screwing it up. The only thing that doesn’t seem to wash out the data out is moving pixels around without changing them. Not sure what I’m missing. Here’s the few different manipulations and what they look like when they wash out.


for(int i = 0; i < frame->height; i++) {
  int offset = i*frame->width*3;
  for(int j = 0; j < frame->width; j++) {
    uchar temp = frame->imageData[offset+(j*3)]*0.114
                    + frame->imageData[offset+(j*3)+1]*0.587
                    + frame->imageData[offset+(j*3)+2]*0.299;
    frame->imageData[offset+(j*3)] = temp;
    frame->imageData[offset+(j*3)+1] = temp;
    frame->imageData[offset+(j*3)+2] = temp;

This one just keeps five frames and then adds them in to create a faded composite, should be simple.

if(0 == memory_frameCounter)
  memory_frames[0] = cvCloneImage(frame);
else if(2 == memory_frameCounter)
  memory_frames[1] = cvCloneImage(frame);
else if(4 == memory_frameCounter)
  memory_frames[2] = cvCloneImage(frame);
else if(6 == memory_frameCounter)
  memory_frames[3] = cvCloneImage(frame);
else if(8 == memory_frameCounter)
  memory_frames[4] = cvCloneImage(frame);
else if(10 <= memory_frameCounter)
  memory_frameCounter = -1;


for(int i = 0; i < frame->height; i++) {
  for(int j =0; j < frame->width*3; j++) {
    memory_agg = frame->imageData[(i*frame->width*3)+j];
    for(int k = 0; k < 5; k++) {
      memory_agg = (memory_agg + memory_frames[k]->imageData[(i*frame->width*3)+j])/2;
    frame->imageData[(i*frame->width*3)+j] = memory_agg;

I just can’t figure out what I’m doing wrong here.

Playing with OpenCV

February 26, 2008 » Geek

OpenCV is a cross platform video library I’ve been playing with. Today I coded up a horizontal mirror effect, took about 30 minutes. I worked out all the byte manipulations on a piece of paper, that took the longest. Coding was a breeze with OpenCV, and I tried out some of the built in effects too, stacking them on top of each other.

Here’s my first version source for the mirror effect, it’s rough since I just translated what I had written down into code. “frame” is a captured IplImage.

int halfsies = frame->width/2;
for(int i = 0; i < frame->height; i++) {
  int offset = i*frame->width*3;
  for(int j = 0; j < halfsies; j++) {
    frame->imageData[offset+(frame->width*3-1)-2-(j*3)] = frame->imageData[offset+(j*3)];
    frame->imageData[offset+(frame->width*3-1)-1-(j*3)] = frame->imageData[offset+(j*3)+1];
    frame->imageData[offset+(frame->width*3-1)-(j*3)] = frame->imageData[offset+(j*3)+2];

Here is the reformed version, cleaner by far.

int halfFrame = frame->width/2;
int frameBytes = frame->width*3-1;
for(int i = 0; i < frame->height; i++) {
  int offset = i*frame->width*3;
  for(int j = 0; j < halfFrame; j++) {
    int jBytes = offset+frameBytes-(j*3);
    int ojBytes = offset+(j*3);
    frame->imageData[jBytes-2] = frame->imageData[ojBytes];
    frame->imageData[jBytes-1] = frame->imageData[ojBytes+1];
    frame->imageData[jBytes] = frame->imageData[ojBytes+2];

And here is what it looks like. The first one is without any other effects, the second is with the OpenCV effect “erode”.

You can get the full source of my fxTest.cpp here if you want it.

The Introduction to programming with OpenCV was a great resource for me.