visualize a few matches
(self, view1, view2, matches_im0, matches_im1, vis_fig)
| 196 | return matches_im_query, matches_im_map |
| 197 | |
| 198 | def visualize_matches(self, view1, view2, matches_im0, matches_im1, vis_fig): |
| 199 | """visualize a few matches""" |
| 200 | n_viz = 20 |
| 201 | num_matches = matches_im0.shape[0] |
| 202 | match_idx_to_viz = np.round(np.linspace(0, num_matches - 1, n_viz)).astype(int) |
| 203 | viz_matches_im0, viz_matches_im1 = matches_im0[match_idx_to_viz], matches_im1[match_idx_to_viz] |
| 204 | |
| 205 | viz_imgs = [] |
| 206 | for i, view in enumerate([view1, view2]): |
| 207 | rgb_tensor = view['img'] * self.image_std + self.image_mean |
| 208 | viz_imgs.append(rgb_tensor.squeeze(0).permute(1, 2, 0).cpu().numpy()) |
| 209 | |
| 210 | H0, W0, H1, W1 = *viz_imgs[0].shape[:2], *viz_imgs[1].shape[:2] |
| 211 | img0 = np.pad(viz_imgs[0], ((0, max(H1 - H0, 0)), (0, 0), (0, 0)), 'constant', constant_values=0) |
| 212 | img1 = np.pad(viz_imgs[1], ((0, max(H0 - H1, 0)), (0, 0), (0, 0)), 'constant', constant_values=0) |
| 213 | img = np.concatenate((img0, img1), axis=1) |
| 214 | vis_fig.imshow(img) |
| 215 | for i in range(n_viz): |
| 216 | (x0, y0), (x1, y1) = viz_matches_im0[i].T, viz_matches_im1[i].T |
| 217 | vis_fig.plot([x0, x1 + W0], [y0, y1], '-+', color=self.cmap(i / (n_viz - 1)), scalex=False, scaley=False) |
| 218 | vis_fig.axis('off') |
| 219 | # vis_fig.set_title('Left: GT Image, Right: Pred Image') |
| 220 | # plt.tight_layout() |
| 221 | # plt.show() |
no outgoing calls
no test coverage detected