Code Monkey home page Code Monkey logo

fisheye-undistorting's Introduction

鱼眼镜头效果校正
Fisheye undistorting

After knowing how to use api of opencv, including calibrating and undistorting, i wanted to figure out how
the undistorting process work. So i viewed http://paulbourke.net/dome/fisheye/ and learnt projection from
image to hemisphere surface, and wrote undistorting in my own way.

Opencv version :

实现了从标定板标定参数, 到校正单张图片, 视频文件和视频流
First my input datas of calibrateing chessboard will locate corner points, then give those points to fisheye
calibrating of opencv which based on Zhengyou Zhang's 1999 paper , this will measure internal and external
parameters, and distortion coefficients. So you can use those parameters to remap every pixels.
I already have wrote functions including undistorting image data, video data and stream.

No opencv version :

实现任意大小图片, 以图片中心为畸变中心, 可以任意扩张输出大小.
后续可能会添加畸变参数和任意位置畸变中心.
根据Paul的网页我们能知道平面到半球上的映射, 当然这只是一半, 还需要将半球上的坐标重新映射到输出平面.
By following Paul's web, first you'd better consider every pixels with polar coordinates and sphere coordinates,
using length and angle to describe pixels, then you can easily calculate whole projection. To undistort,
all you need to do is to make every coordinates on hemisphere map to the new plane - your output plane.
projection
由上图可知反畸变其实就是将输入图像input平面上坐标映射到新平面output上, 利用极坐标系和相似三角形(不需要球坐标系的theta).
一般我们已知r和L(r是镜头半径, L是input和output平面的距离, 一般情况下r等于L), 则利用图上中关系式可求每一点坐标前后映射.
We can easily knowing what we actually want is phi and distance to the center of one point, using similar
rectangle you can transform distance to center on output plane and input plane (this actually uses angle theta), and both output plane and input plane have same phi.
I wrote three version : without interpolation, with interpolation and optimizing with matrix. Dealing gray images only, and i didn't consider distorting parameters, maybe i will add it in future. I only upload last two version.
Input:
mat
Outputs in three way:
实际上真正从原图映射到输出图像的原始数据是会像下面这张无插值的输出, 黑色的空缺通过插值算法填充 :
Without interpolation :
res1
线性插值 :
Linear interpolation :
res2
矩阵加速, 由于矩阵运算的局限性, 在边缘区域所有扩展都是边缘拉伸, 但是不影响上图一样的有效区域内变化 : Speed up by using mtrix :
res3

代码里有两个版本, 前一个遍历每一pixel进行插值和映射, 后一个利用矩阵加速, 在我的数据和设备能上提升43倍, 满足实时处理.
Every 640*480 image on my very old computer using second way cost 17.25s, and the last way cost 0.395s, speed
up for 4300%

fisheye-undistorting's People

Contributors

mirusumbra avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

wizardst

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.