I live in Omaha.
 
Navigation
 
Search
 
Random Image
DSC_0009.jpg
 
Me. Elsewhere.
 
Archives
 
Darcy
 
Recently Read
 
Things I Like
kohana
 
License
 
Playing with OpenCV

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 - Permalink
Categories: Geek
Tags: , , , , ,
You can leave a comment, or trackback from your own site.
 
Possibly Related Posts
 
Adjacent Posts
 
Comments

One Response to “Playing with OpenCV”

  1. VelvetCache.org » John Hobbs Blog » Blog Archive » libcvfx Says:

    [...] been playing with OpenCV recently and was having troubles with creating effects. That’s all over now thanks to the [...]

 
Copyright © 2006 - 2010 John Hobbs
get userping