Skip to content

Dewarping algorithm

Mathieu Favreau edited this page Dec 15, 2019 · 6 revisions

Introduction

The dewarping algorithm is what allows us to go from a fisheye image to an image with little distortion. The algorithm we developed is based on the code of Katherine A. Scott which can be found here with some explanations. We were not satisfied with the level of distortions obtained with this algorithm, so we modified it so match our needs.

How it works

In the following image, we can see the dewarping process used by Katherine A. Scott with only a 90 degrees region dewarped.

Katherine A. Scott algo

In the code, the class DonutSlice contains all the parameters of the donut slice. This includes the center (x, y) of the donut in the image (in pixels), the radius of the inner and outer circles defining the donut, the angle at the center of the slice as well as the angle span of the slice (the middle angle is 0 degrees and the angle span 90 degrees in the image example above).

As you can see, there is still quite some distortion in the high end of the dewarped image. This is normal, as there are less pixels sampled in the top of the donut slice than in the bottom (compare the arc lengths). To improve this, we modify the donut slice as showed in the next image.

Our algo

While it hardly looks like a donut anymore, we will still call it this way for simplicity. As you can see, the middle circle is now a lot bigger and no longer centered on the outer circle. This has the effect of increasing the inner arc length of the slice and therefor improving the sampling in the top of the dewarped image. A side effect is we actually get a bigger field of view in the dewarped image.

It's use with the detection

Because our detection model is not trained on fisheye iamges, we need to create dewarped images first as the next image shows.

Video processing

The number of image and their angle span is configurable as mentionned in the next section.

Config parameters

The steno configuration file allows the user to modify how he dewarps the fisheye images inputted to the system.

  • FISH_EYE_ANGLE : The angle of the fisheye lens as stated by the manufacturer
  • IN_RADIUS : The radius of the inner circle before we apply any modifications (see first image).
  • OUT_RADIUS : The radius of the outer circle before we apply any modifications (see first image)
  • TOP_DISTORSION_FACTOR : Will increase the size of the the new inner circle (formula is IN_RADIUS * TOP_DISTORSION_FACTOR to get new one, this might not be optimal)
  • BOTTOM_DISTORSION_FACTOR : Allow the modification of the outer circle radius (note it will also move it's center, a value of 1 means the center is the same as the base inner cricle, a value of 0 means the center is the same as the modified inner circle)

The next configuration parameters are for the dewarping required with the detection.

  • ANGLE_SPAN : The angle span of each dewarped image used for the detection
  • DETECTION_DEWARPING_COUNT : The number of dewarped images used for detection

Extra visualisation

The following image is the representation of a donut slice with it's modified donut slice (new donut slice) and the obtained dewarp parameters. This can be useful if trying to understand the code in further details.

Dewarp parameters