0
0
Computer Visionml~10 mins

Homography and image alignment in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compute the homography matrix using OpenCV.

Computer Vision
import cv2
import numpy as np

# pts_src and pts_dst are arrays of corresponding points
H, status = cv2.findHomography(pts_src, pts_dst, [1])
Drag options to blanks, or click blank then click option'
Acv2.LMEDS
Bcv2.RANSAC
Ccv2.USAC_DEFAULT
Dcv2.USAC_FAST
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method other than RANSAC may cause poor homography estimation.
Not specifying a method leads to default behavior which might not handle outliers well.
2fill in blank
medium

Complete the code to warp the source image to align with the destination image using the homography matrix.

Computer Vision
height, width = img_dst.shape[:2]
img_aligned = cv2.warpPerspective(img_src, [1], (width, height))
Drag options to blanks, or click blank then click option'
AH
BH.T
Cnp.linalg.inv(H)
Dnp.eye(3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the inverse of H instead of H causes incorrect warping.
Passing identity matrix results in no transformation.
3fill in blank
hard

Fix the error in the code that extracts matching keypoints from two images for homography estimation.

Computer Vision
matches = bf.match(des1, des2)
matches = sorted(matches, key=lambda x: x.distance)
pts_src = np.float32([kp1[[1]].pt for m in matches]).reshape(-1,1,2)
Drag options to blanks, or click blank then click option'
Am.queryIdx
Bm.trainIdx
Cm.distance
Dm.imgIdx
Attempts:
3 left
💡 Hint
Common Mistakes
Using trainIdx instead of queryIdx swaps source and destination points.
Using distance or imgIdx causes attribute errors.
4fill in blank
hard

Fill both blanks to create a dictionary of aligned images and their homography matrices.

Computer Vision
aligned_data = {
    'image': img_src, 
    'homography': [1], 
    'status': [2]
}
Drag options to blanks, or click blank then click option'
AH
Bstatus
Cmatches
Dimg_aligned
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing matches with status causes incorrect data storage.
Using img_aligned instead of H for homography is incorrect.
5fill in blank
hard

Fill all three blanks to filter good matches and extract corresponding points for homography.

Computer Vision
good_matches = [m for m in matches if m.distance < [1]]
pts_src = np.float32([kp1[[2]].pt for m in good_matches]).reshape(-1,1,2)
pts_dst = np.float32([kp2[[3]].pt for m in good_matches]).reshape(-1,1,2)
Drag options to blanks, or click blank then click option'
A30
Bm.queryIdx
Cm.trainIdx
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using too low a threshold filters out good matches.
Swapping queryIdx and trainIdx reverses source and destination points.