This uses an input like:
To generate an output like:
This is the view around from the crossroad at which the Atria BLR office is located.
The main modules required for Panorama generation from single shot taken with a fisheye lens, where the principal axis is vertical, are:
This is manually determined here, by clicking on the approximate center point [Cx
Cy], and subsequently selecting 2 points to denote the inner and outer radii of the
fisheye image [R1x R1y], [R2x R2y]. These points are used to determine the
inner and outer radii as R1 and R2
R1 = R1x-Cx
R2 = R2x-Cx
These parameters, C, R1 and R2 determine the coordinate system that is, in turn, used to define the mapping in the next section.
The fisheye image resembles a donut, because the region defined by the inner radius, centered at the center, is not processed. Only the annular region from the inner to the outer radius is used; hence donut. The central region is not used to avoid the extreme distortion that would be caused if it were.
First, source and destination image sizes are determined as [Ws Hs] and [Wd Hd]
Wd = 2.0*((R2+R1)/2)*pi
Hd = (R2-R1)
Ws = img.width # img is the source fisheye image
Hs = img.height
Then, the following transformation is used to map which source pixels the
destination pixels originate from:
r = (float(yD)/float(Hd))*(R2-R1)+R1
theta = (float(xD)/float(Wd))*2.0*np.pi
xS = Cx+r*np.sin(theta)
yS = Cy+r*np.cos(theta)
Here, [r theta] coordinates in the fisheye image, for each of the destination pixels [xD yD] are found using the parameters determined earlier R1 and R2, with the origin at C. Then, the coordinate origin is shifted to the origin of the image to get [xS yS].
The arrays xmap and ymap hold the source coordinates from which destination
coordinate [xD yD] originates:
xS = xmap[xD yD]
yS = ymap[xD yD]
The map generated in the previous section is applied to the fisheye image (using
bilinear interpolation to construct values for integer pixel values, where the map
contains floating values). OpenCV function 'remap' is used to do this.
output = cv2.remap(img,xmap,ymap,cv2.INTER_LINEAR)
The function 'remap' transforms the source image using the specified map:
dst(xD, yD) = src(xmap(xD,yD),ymap(xD,yD))
where, values of pixels with non-integer coordinates are computed using one of available interpolation methods.
xmap and ymap can be encoded as separate floating-point maps in map1 and map2 respectively, or interleaved floating-point maps of (x,y) in map1 , or fixed-point maps created by using cv2.convertMaps(). The reason you might want to convert from floating to fixed-point representations of a map is that they can yield much faster (~2x) remapping operations. In the converted case, map1 contains pairs (cv2.Floor(x),cv2.Floor(y)) and map2 contains indices in a table of interpolation coefficients.
This function cannot operate in-place.
Copyright © 2015-16 Atria Logic Inc.