Undistortion
As we have alluded to already, there are two things that one often wants to do with a calibrated camera. The first is to correct for distortion effects, and the second is to construct three-dimensional representations of the images it receives. Let's take a moment to look at the first of these before diving into the more complicated second task in Chapter 12.
OpenCV provides us with a ready-to-use undistortion algorithm that takes a raw image and
the distortion coefficients from cvCalibrateCamera2() and
produces a corrected image (see Figure 11-12).
We can access this algorithm either through the function cvUndistort2(), which does everything we need in one shot, or through the pair
of routines cvInitUndistortMap() and cvRemap(), which allow us to handle things a little more
efficiently for video or other situations where we have many images from the same camera.
[185]

Figure 11-12. Camera image before undistortion (left) and after undistortion (right)
The basic method is to compute a distortion map, which is then used
to correct the image. The function cvInitUndistortMap()
computes the distortion map, and cvRemap() can be used to
apply this map to an arbitrary image.[186] The function cvUndistort2() does one after
the other in a single call. However, computing the distortion map is a time-consuming
operation, so it's not very smart to keep calling cvUndistort2() if the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access