mapping with trapezoidal and barrel distortion

livio's icon

Hello Jitterers!
I'm working on a motion tracking system. Two IR cameras and three active markers (to track three users). I'm using some objects of cv.jit and they are very useful.

The cameras mount fisheye lenses and are diagonal to the tracked area. So what I get is a very distorted image where everything fits in, and that's great.

Instead of deforming the image to get rid of the optical and trapezoidal distortion, avoiding heavy manipulations of useless pixels, I'd like to read the XY values (plane image related) and map them "mathematically". This way the process is thousands times lighter and I'll keep my frame rate at 30fps.

Since in every exhibitions the cameras will be in (slightly) different positions, I would avoid any strict mathematic formula and would go for a sort of calibration/interpolation system..
So to have a sort of lightweight look-up-table process once the calibration is done. I'm imagining a rectangular grid (to obtain) and it's real correspondant with barrel and trapezoidal deformation..

What do you think about? Any idea how to implement this "geometrical mapping"?
Cheers,
Livio

livio's icon

Ok, I've been investigating for a while and answer seems to be Spatial Mapping (a.k.a. Tutorial 39)
More precisely the "stretch matrix" used as the table to lookup.
I still miss how to switch the process the other way around.
I mean, to ask this matrix the value and get the col/row index.
So that tracking a point within the distorted image, and performing a getcell to the opposite-to-the-stretch matrix I'll get the "rectangular" value.
How to calculate this opposite-to-the-stretch matrix?
I know, I know, I'd need some basic math revision..
Livio

jazmatajz's icon

i posted few days ago camera callibration patch (topic Name) . With fisheye lens
probably you will have some problems. but You can give it a try.

livio's icon

Hi Jaz,
thank you for your patch. It's very interesting. As far as I understand you use cv.jit to find automatically your reference marks, nice. The second part where you create you repos matrix it's kind of obscure at my eyes. It would be of great help to have it commented to get easier access to it..
Anyhow, instead of threating the whole image, I'm still looking for a mathematical method to reverse the reference matrix (done by hand and used as lookup by jit.repos) to just ask for one value and get the "squary" one.
If I got it right, jit.repos do a complete scan of the input matrix find a per-pixel new placement, and output the new matrix.
Since I need to spatiallly map a tracked point (one coord), I would turn the process upside down, preparing an inversed matrix, but I can't see how.
I don't know if I'm clear.. :/ Please check the example patch attached.
In other posts, Jeremy Bernstein, kind of proposed to get into the matter but the discussion vanished.
Livio