distortion map

hi all
i need to make a square image sequence fish eyed or vice versa.

i have a bunch of image sequences that make up a 360 degree image from a series of fish eye cameras. i need to warp these images before stitching them together and haven’t found any existing solutions to do this. thought of automating the photomerge js script in photoshop but the deformations aren’t consistent enough.

so what i want to do is write a simple app that applies the same distortion to a folder of images. I have been looking at open CV as I thought I could use the remap function, but I don’t know how to go about generating the IplImage distortion maps.

I have a manually edited before/after still and grid that I can use as a source. Can anyone suggest a way to do this? is there a handy way to use open cv somehow? or would i be better off mapping the vertices using open gl somemhow?

this seems so simple but i am quite stuck with how to do this beyond quad warps!