课程作业的一个题目,找了代码加了注释。
import numpy as np
import cv2
class Stitcher:
def stitch(self, images, ratio=0.75, reprojThresh=4.0,
showMatches=False):
# 检测出关键点,局部不变描述符
(imageB, imageA) = images
(kpsA, featuresA) = self.detectAndDescribe(imageA)
(kpsB, featuresB) = self.detectAndDescribe(imageB)
print("关键点个数",len(kpsA),len(kpsB))
# 特征匹配
M = self.matchKeypoints(kpsA, kpsB,
featuresA, featuresB, ratio, reprojThresh)
# 如果特征匹配返回None
if M is None:
return None
# 将图像粘合在一起
(matches, H, status) = M
# 根据单应性矩阵进行矫正图片
result = cv2.warpPerspective(imageA, H,
(imageA.shape[1] + imageB.shape[1], imageA.shape[0]))
# imageA.shape[1]=400,imageB.shape[1]=400,imageA.shape[0]=533
# result.shape[0]=533,result.shape[1]=800