Skip to main content


Showing posts from May, 2009

Swig with C++ and external libs

This is the kind of problem I work out how to solve, then I forget... and eventually have to do again... So more for my sake here is how to compile a python extension in c++ that has external libraries like opencv. Automatically wrapped with swig from distutils...

So first up I have a random library of C++ that I want to use from python. One such C file is doing some low level math on an opencv IPL image. Since I want to use this in python but require it to be fast, I need to create an extension.

// The header file I want to wrap.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "cv.h"

void remove_corneal_reflection(IplImage *image, IplImage *threshold_image, int sx, int sy, int window_size,
     int biggest_crr, int &crx, int &cry, int& crr, int *valid_point_calc);

This has a few normal includes and "cv.h". This is refering to the opencv installed NOT in the default dir but in /usr/local/.

Next is the instructions for swig to…

Eye Locating

Image capturing is happening with the module. Object Detection is using an ObjectDetect class I wrote that wraps the cvHaarDetectObject from the opencv library.

Just for fun the green box is drawn with pygame, the Red boxes are drawn with opencv. And the whole thing is rendered with pygame.