Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv: Correcting these distorted images

What will be the procedure to correct the following distorted images ? It looks like the images are bulging out from center. These are of the same QR code, and so a combination of such images can be used to arrive at a single correct and straight image. Please advice.

enter image description hereenter image description hereenter image description here

like image 440
Tabish Saifullah Avatar asked Jul 05 '15 08:07

Tabish Saifullah


1 Answers

The distortion you are experiencing is called "barrel distortion". A technical name is "combination of radial distortion and tangential distortions"

The solution for your problem is openCV camera calibration module. Just google it and you will find documentations in openCV wiki. More over, openCV already has built in source code examples of how to calibrate the camera.

Basically, You need to print an image of a chess board, take a few pictures of it, run the calibration module (built in method) and get as output transformation matrix. For each video frame you apply this matrix (I think the method called cvUndistort()) and it will straighten the curved lines in the image. Note: It will not work if you change the zoom or focal length of the camera.

If camera details are not available and uncontrollable - then your problem is very serious. There is a way to solve the distortion, but I don't know if openCV has built in modules for that. I am afraid that you will need to write a lot of code.

Basically - you need to detect as much as possible long lines. Then from those lines (vertical and horizontal) you build a grid of intersection points. Finally you fit the grid of those points to openCV calibration module. If you have enough intersection points (say 20 or more) you will be able to calculate the distortion matrix and un-distort the image.

You will not be able to fully calibrate the camera. In other words, you will not be able to run a one time process that calculates the expected distortion. Rather - in each and every video frame, you will calculate the distortion matrix directly - reverse it and un-distort the image. If you are not familiar with image processing techniques or unable to find a reliable open source code which directly solves your problem - then I am afraid that you will not be able to remove the distortion. sorry

like image 195
DanielHsH Avatar answered Sep 22 '22 18:09

DanielHsH