in optical_flow_flownet2_homography.py [0:0]
def getimage(img1_path, img2_path, size=None):
frame1 = cv2.imread(img1_path)
frame2 = cv2.imread(img2_path)
if size is not None:
frame1 = cv2.resize(frame1[:, :, ::-1], (size[1], size[0]))
frame2 = cv2.resize(frame2[:, :, ::-1], (size[1], size[0]))
imgH, imgW, _ = frame1.shape
(kpsA, featuresA) = detectAndDescribe(frame1)
(kpsB, featuresB) = detectAndDescribe(frame2)
try:
(_, H_BA, _) = matchKeypoints(kpsB, kpsA, featuresB, featuresA)
except Exception:
H_BA = np.array([1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0]).reshape(3, 3)
NoneType = type(None)
if type(H_BA) == NoneType:
H_BA = np.array([1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0]).reshape(3, 3)
try:
np.linalg.inv(H_BA)
except Exception:
H_BA = np.array([1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0]).reshape(3, 3)
img2_registered = cv2.warpPerspective(frame2, H_BA, (imgW, imgH))
frame1_tensor = torch.from_numpy(frame1).permute(2, 0, 1).contiguous().float()
frame2_tensor = torch.from_numpy(frame2).permute(2, 0, 1).contiguous().float()
frame2_reg_tensor = (
torch.from_numpy(img2_registered).permute(2, 0, 1).contiguous().float()
)
return frame1_tensor, frame2_tensor, frame2_reg_tensor, H_BA