This is snippet program implements dewarped image extraction algorithm exactly as presented in this research paper:
"High Quality Image Correction Algorithm With Cubic Interpolation for Fish-eye Lens" by Mori Takahiro et al.
CAUTION: Main part of this paper - high quality image correction - is not handled here.
There are many information found on Web regarding getting panorama image from fisheye image, but these are limited to show off each technique. My snippet shows exact code for getting image from your fisheye source image freely regarding:
- Angle
- Zooming
You can get images as if you are shitting in the center of fisheye image, and looking around. I call this as "window" of the fisheye image, so the class name is FishEyeWindow. Let's see what you can get below.
Angle | Parameter |
---|---|
left | alpha=-270.000000, beta=135.000000, theta=270.000000, zoom=0.300000 |
center | alpha=-270.000000, beta=0.000000, theta=270.000000, zoom=0.300000 |
right | alpha=-270.000000, beta=-135.000000, theta=270.000000, zoom=0.300000 |
up | alpha=0.000000, beta=90.000000, theta=0.000000, zoom=0.300000 |
down | alpha=0.000000, beta=-90.000000, theta=0.000000, zoom=0.300000 |
Once you start python snippet like this:
$ python fisheye360.py sample.png
Program will stay running waiting for your control.
Hit followings to move your view:
'r' or 'f' to zoom
'g' or 't' to rotate alpha
'h' or 'y' to rotate beta
'j' or 'u' to rotate theta
's' to save current view to ./result.png
Hit ESC to exit.
Opencv 2.x would be ok, or try 3.x if you see anything wrong.
The FishEyeWindow class is designed based on:
- The center of source image is the center.
- Top/bottom or left/right part of image can be cut, as long as the center is the center.
- Small workaround done for hiding an issue - orthant exchange; explained below.
If I follow simply as the original math, the result image has problem:
- What should be on the orthant I is on the II, and the II on the I.
- Tha same thing for III and IV.
Then I implemented simple workraound to exchange orthant as you can find in the source.
This is just have interpreted math equations into python code, feel free to use.