Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The cv2.findHomography function uses cv2.RANSAC as the robust method to estimate the homography matrix while ignoring outliers.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the inverse of H instead of H causes incorrect warping.
Passing identity matrix results in no transformation.
✗ Incorrect
The warpPerspective function uses the homography matrix H to transform the source image to align with the destination image.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using trainIdx instead of queryIdx swaps source and destination points.
Using distance or imgIdx causes attribute errors.
✗ Incorrect
For the source image keypoints, we use m.queryIdx to get the index of the keypoint in kp1 corresponding to each match.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing matches with status causes incorrect data storage.
Using img_aligned instead of H for homography is incorrect.
✗ Incorrect
The dictionary stores the homography matrix H and the status mask returned by findHomography to indicate inliers.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too low a threshold filters out good matches.
Swapping queryIdx and trainIdx reverses source and destination points.
✗ Incorrect
We filter matches with distance less than 50, then extract source points using m.queryIdx and destination points using m.trainIdx.