| Days | |
| Hours | |
| Minutes | |
| Seconds |
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.
Baseline
This is my normal image I get from my cheap labtec webcam.
And yes, I am that good looking.

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

Mirror
Copies and flips the left side onto the right.


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

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

Memory
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.

Pixelize
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.
Posted March 10th, 2008 - PermalinkI’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.
Monochrome
1 2 3 4 5 6 7 8 9 10 11 | 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; } } |


Memory
This one just keeps five frames and then adds them in to create a faded composite, should be simple.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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; memory_frameCounter++; 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.
Posted March 2nd, 2008 - PermalinkI’m taking a GUI design class right now and for slightly odd reasons he is having us do mini-projects in Photoshop and Flash. For the last bit of the Photoshop one we were supposed to cut Lance Armstrong out of a picture and put him in any background we wanted. I choose the gates to Mordor and I’m quite proud of the results.
Click through for the full size, it’s worth it I think.
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.
1 2 3 4 5 6 7 8 9 | 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.
1 2 3 4 5 6 7 8 9 10 11 12 | 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.
Posted February 26th, 2008 - PermalinkI’m getting more and more confident in GIMP now. Last night I forced myself to do some layout work for Leigh’s dance studio site in GIMP and I’m very satisfied. I have the example of about two hours of work. Yes, I probably could have made it in about one if I had Photoshop, but thats all part of getting better at something. I may soon feel confident enough to never fall back onto Photoshop again. Anyway, here’s the layout so far, below is a snippet and it links to the full size 800×600 layout. Really only the header is “finished”. And even it is going to be a bit lighter in shade.
Posted November 30th, 2006 - Permalink