基于双鱼眼的全景视频图像拼接CV算法实战
该项目中,有些同学不会可视化特征点。我统一写一下,真心很简单。
函数
我们定义一个函数make_matching_plot。你需要传入特征点匹配的图一和图二,以及匹配的特征点信息和可视化图像的保存地址。
import cv2
import pdb
import numpy as np
from matplotlib import cm
def make_matching_plot(image0, image1, mkp0, mkp1, save_path):
img_matches = np.zeros((max(image0.shape[0], image1.shape[0]), 100+image0.shape[1] + image1.shape[1], 3), dtype=np.uint8)
img_matches[:image0.shape[0], :image0.shape[1], :] = image0
img_matches[:image1.shape[0], -image1.shape[1]:, :] = image1
color_list = np.linspace(0, 1, len(mkp0))
np.random.shuffle(color_list)
colors = cm.rainbow(color_list)
for (pt0, pt1), color in zip(zip(mkp0, mkp1), colors):
img0_coord = (int(pt0[0][0]), int(pt0[0][1]))
img1_coord = (int(pt1[0][0])+100+image0.shape[1], int(pt1[0][1]))
color_bgr = tuple(int(c * 255) for c in color[:3])
cv2.line(img_matches,img0_coord, img1_coord, color_bgr, 2, lineType=cv2.LINE_AA)
cv2.circle(img_matches, img0_coord, 1, color_bgr, 4)
cv2.circle(img_matches, img1_coord, 1, color_bgr, 4)
cv2.imwrite(save_path, img_matches)
代码中
Algorithm/outer_api.py中120行位置
"""add two side features points to gen homograpy"""
src_pts_L = np.float32([kp1_L[m.queryIdx].pt for m in good_L]).reshape(-1, 1, 2)
dst_pts_L = np.float32([kp2_L[m.trainIdx].pt for m in good_L]).reshape(-1, 1, 2)
src_pts_R = np.float32([kp1_R[m.queryIdx].pt for m in good_R]).reshape(-1, 1, 2)
dst_pts_R = np.float32([kp2_R[m.trainIdx].pt for m in good_R]).reshape(-1, 1, 2)
# pdb.set_trace()
# only superpoints
make_matching_plot(overlap_left_img1,overlap_left_img2, src_pts_L, dst_pts_L, 'left_sift.png')
make_matching_plot(overlap_right_img1,overlap_right_img2, src_pts_R, dst_pts_R, 'right_sift.png')
make_matching_plot(overlap_right_img1,overlap_right_img2, kp1_L_cnn.reshape(-1, 1, 2), kp2_L_cnn.reshape(-1, 1, 2), 'left_superpoint.png')
make_matching_plot(overlap_right_img1,overlap_right_img2, kp1_R_cnn.reshape(-1, 1, 2), kp2_R_cnn.reshape(-1, 1, 2), 'right_superpoint.png')
结果
大家可以猜猜下面哪些是sift+NN的匹配和superpoint+superglue的匹配结果