
might help in some cases
/!\ UPDATE ! /!\ as mentionned by C4RLO5 and Makc3D in the comments, homography can be part of the AR video stream process.
saqoosha did 2 versions with Pixelbender and a displacementmap filter.
His benchmark simply makes this class pointless ( +/- 75 times faster :) )
check saqoosha’s article here
so this is a script to perform a transformation that my poor english might not suffice to explain: homography
now what it does is it takes a projected picture and given 4 control points, it’ll somehow undistort the projected image to retrieve a ‘flat’ map of the original.
a demo worth a thousand words:
on the top half, we have a jpg showing a projected square. you can move the handles around to change the zone to crop.
the small square underneath is the actual homography: the unprojected version of the cropped area.
and on the bottom half, I’ve used Thomas Pfeiffer’s Distort class to remap the homographic version onto 4 arbitrary points (you can also drag them).
it’s quite CPU eating but we should use it as a pre-process .
I tried to make an idiot-proof class so it goes like this:
var target:BitmapData = Homography.setTransform( source, W, H, p1, p2, p3, p4 );
where source is the source bitmapData, W / H are the desired dimensions for homography and p1,p2,p3 and p4 are the control points.
one could use it to recreate a 3D space from pictures 2 or more pictures, say like photosynth (somehow). or just collect the top, front and side maps of a milk box then unwrap them then remap it to a 3D box.
I’m thinking of some kind of motion portrait based on triangles that would use this trick to perform morphing.
well, lots of potential uses.
the class is available here: Homography.as
and the fla file here: homographie.fla
/!\ you need the Distort class to run the fla/!\
et voila!
C4RL05
on Apr 14th, 2009
@ 12:51 pm:
Thanks so much, this can be very useful for pattern recognition. Great blog, lots of interesting stuff.
makc3d
on Apr 21st, 2009
@ 7:54 am:
indeed this is half of what FLARToolkit does
Alan Shaw
on May 16th, 2009
@ 5:28 pm:
Great but would it not be cleaner using flash 10 warping? I believe that the Distort class (essential up to now) is superseded by flash 10.
nicoptere
on May 16th, 2009
@ 8:53 pm:
hi all, thanks for the comments.
C4RLO5 > thanks :)
makc3d > not quite half the job :)
recognizing the fudicial pattern is important yet the trickiest part is to find the invert projection matrix for the given points.
Alan > indeed the FP10 drawing methods would be both cleaner and faster.
I haven’t started working with it yet … shame on me.
but maybe you were talking about th algorithm itself in which case I have to admit that I didn’t understand what you were saying.
Alan Shaw
on May 24th, 2009
@ 6:40 pm:
All I’m saying is, is this not the same general 2D warping problem I addressed in AstroMorpher?
The Distort class was created to get around the pre-Flash 10 lack of built-in perspective transformation (using the Matrix class you are limited to affine transformations only). So Distort cuts up the polygon into small triangles and thus minimizes the mapping error.
But in Flash 10 there is drawTriangles() which can do the mapping even on non-affine transformations.