Question: Write the warp _ image and image _ rectification functions. WRITE ONLY UNDER WRITE YOUR CODE HERE 1 . 4 . 4 Problem 3 .
Write the warpimage and imagerectification functions. WRITE ONLY UNDER WRITE YOUR CODE HERE
Problem : Uncalibrated Stereo Image Rectification points
In Assignment you performed epipolar rectification with calibrated stereo cameras. Rectifying a pair of images can also be done for uncalibrated camera images. Using the fundamental matrix we can find the pair of epipolar lines li and li for each of the correspondences. The intersection of these lines will give us the respective epipoles e and e Now to make the epipolar lines to be parallel we need to map the epipoles to infinity. Hence, we need to find a homography that maps the epipoles to infinity.
The rectificaton method has already been implemented for you. You can get more details from the paper Theory and Practice of Projective Rectification by Richard Hartley.
Your task is to:
complete the warpimage function Hint: You may reuse some of the codes from Homework but this time we perform the warp of the full image content, ie the output image will contain the full image content in the source image. Thus, the size of the output image may not be same as the size of the source image. Calculate the targeted size of the output image by piping four corners through the forward transformation
complete the imagerectification function to find the rectified images. Use the provided computematchinghomographies to compute the rectification transformation matrices.
plot the parallel epipolar lines using the plotepipolarlines function from above.
The figure below gives you an idea on how the final results look Note that the two images may not be in the same shape Show your result for matrix and warrior.
def warpimageimage H:
n
Performs the warp of the full image content.
Calculates bounding box by piping four corners through the transformation.
Args:
image: Image to warp
H: The image rectification transformation matrices.
Returns:
Out: An inverse warp of the image, given a homography.
minx miny: The minimummaxmum of warped image bound.
### YOUR CODE HERE
### END YOUR CODE
return out, minx miny
: from math import floor, ceil
def computematchinghomographiese F im points points:
"This function computes the homographies to get the rectified images.
Args:
e: epipole in image
F : the fundamental matrix think about what you should be passing: F or FT
im: image
points: corner points in image
points: corresponding corner points in image
Returns:
H: the image rectification transformation matrix for image
H: the image rectification transformation matrix for image
# calculate H
width im shape
height imshape
Tnpidentity
T width
T height
ehat T dot e
normv nplinalg.normehat :
costheta ehat normv
sintheta ehat normv
if costheta :
costheta costheta
sintheta sintheta
R nparraycostheta, sintheta,
sintheta, costheta,
G npidentity
Gehatehat costheta ehat sintheta
H np dotnpdot G R T
calculate H
eprime npzeros
eprimee
eprime e
eprime e
eprimee
eprimee
eprime e
v nparray
M eprime.dotF npoutere v
pointshat HdotMdotpointsTT
pointshat HdotpointsTT
W pointshat pointshat :reshape
b pointshat pointshat:reshape:
least square problem
a a a nplinalg.lstsqW b rcondNone
HA npidentity
HA nparraya a a
H HA dotH dotM
return H H
: def imagerectificationim im points points:
This function provides the rectified images along with the new corner
points as
images with corner correspondences
Args:
im: image
im: image
points: corner points in image
points: corner points in image
Returns:
rectifiedim: rectified image
rectifiedim: rectified image
newcor: new corners in the rectified image
newcor: new corners in the rectified image
n
YOUR CODE HERE
END YOUR CODE
return rectifiedim rectifiedim newcor newcor
:
This code is for you to plot the results.
The total number of outputs is images in pairs
imgids matrix "warrior"
for imgid in imgids:
printpimgidimgidpng
I imreadpimgidimgidpng
I imreadpimgidimgidpng
cor nploadpimgidcornpy
cor nploadpimgidcornpy
rectifiedim rectifiedim rectcor rectcor
magerectificationI I cor cor
rectF fundamentalmatrixrectcor rectcor
plotepipolarlinesrectifiedim rectifiedim rectF rectcorsqcup
rrectcor
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
