various code samples


I got around to cleaning up and posting a couple of useful bits and pieces of code last week:

  • Movement along bezier curves
  • Contour analysis - ellipse fitting, point in polygon, line finding
  • Statistic recorder - a simple class for tracking running streams of data

Find everything here:

hopefully more to come…


Really great stuff chris! I’m a big fan of your projects and code examples =)

I noticed you posted an update version of Warp too. I saw you included the FBO classes, but they don’t seem to be used. Is that correct or am I missing something? I’ve been using your older Warp stuff on a project and was interested if you’ll be adding in the FBO stuff into your updated example.

Thanks and keep up the great work!


mega nice !!! :smiley:


Thanks, your blog is great, helped to get me going! These are great examples! :smiley:


Hi Chris. Thanks for the code examples. I tried to get the FakeMultiTouchScreen example to compile on my mac with oF_005 but i failed. :slight_smile: Maybe somebody has a working xcode project?

Thanks a lot



this is amazing!!! thanks :slight_smile:


i’m glad these are useful - post if you make some updates or nice additions to them!

stiwi - sorry yes, I still haven’t updated that code. it is from a really old release and it think quite a few things are broken on it… will try to fix that example this week.

cerupcat - ah, no i wasn’t using fbo’s in that example, perhaps I left it in by mistake…


hey chris,

i’m just working through your super-useful contour analysis examples. do you know if there’s a method for creating a bounding rectangle (oriented to fit around the shape of the tracked object) instead of an ellipse?

thanks for these algorithms!




look for “CvBox2D”

note that from version to version of opencv they have changed angle from radians to degrees, so be careful :slight_smile:

  • zach


i discovered cvMinAreaRect, which takes a list of contour points and outputs an rectangle that tightly hugs the blog … with an angle, centerpoint, width and height.

from there, it’s possible to get the coordinates of the enclosing rect using cvBoxPoints();


here’s the code:

void fitBox( vector <ofPoint>  & contour, CvBox2D32f & box)  
    CvPoint * pointArray = new CvPoint[contour.size()];  
    for( int i = 0; i < contour.size(); i++){  
    	pointArray[i].x = 	contour[i].x;  
    	pointArray[i].y =	contour[i].y;  
	CvMat pointMat = cvMat( 1, contour.size(), CV_32SC2, pointArray);  
	box = cvMinAreaRect2(&pointMat, 0);  


ah yeah, that’s right box2d is what it returns… nice function there, thanks!

interesting, I was skimming through that section and there is a point in polygon test:

I had no idea… we keep going back to paul bourke :slight_smile:

take care!

  • zach

well, the nice thing about the paul bourke site is that each section contains an image describing the algorithm.



Are these still available somewhere?