Plot matches for a pair of existing images. Args: kpts0, kpts1: corresponding keypoints of size (N, 2). color: color of each match, string or RGB tuple. Random if not given. lw: width of the lines. ps: size of the end points (no endpoint if ps=0) indices:
(kpts0, kpts1, color=None, lw=1.5, ps=4, indices=(0, 1), a=1.)
| 68 | |
| 69 | |
| 70 | def plot_matches(kpts0, kpts1, color=None, lw=1.5, ps=4, indices=(0, 1), a=1.): |
| 71 | """Plot matches for a pair of existing images. |
| 72 | Args: |
| 73 | kpts0, kpts1: corresponding keypoints of size (N, 2). |
| 74 | color: color of each match, string or RGB tuple. Random if not given. |
| 75 | lw: width of the lines. |
| 76 | ps: size of the end points (no endpoint if ps=0) |
| 77 | indices: indices of the images to draw the matches on. |
| 78 | a: alpha opacity of the match lines. |
| 79 | """ |
| 80 | fig = plt.gcf() |
| 81 | ax = fig.axes |
| 82 | assert len(ax) > max(indices) |
| 83 | ax0, ax1 = ax[indices[0]], ax[indices[1]] |
| 84 | fig.canvas.draw() |
| 85 | |
| 86 | assert len(kpts0) == len(kpts1) |
| 87 | if color is None: |
| 88 | color = matplotlib.cm.hsv(np.random.rand(len(kpts0))).tolist() |
| 89 | elif len(color) > 0 and not isinstance(color[0], (tuple, list)): |
| 90 | color = [color] * len(kpts0) |
| 91 | |
| 92 | if lw > 0: |
| 93 | # transform the points into the figure coordinate system |
| 94 | transFigure = fig.transFigure.inverted() |
| 95 | fkpts0 = transFigure.transform(ax0.transData.transform(kpts0)) |
| 96 | fkpts1 = transFigure.transform(ax1.transData.transform(kpts1)) |
| 97 | fig.lines += [matplotlib.lines.Line2D( |
| 98 | (fkpts0[i, 0], fkpts1[i, 0]), (fkpts0[i, 1], fkpts1[i, 1]), |
| 99 | zorder=1, transform=fig.transFigure, c=color[i], linewidth=lw, |
| 100 | alpha=a) |
| 101 | for i in range(len(kpts0))] |
| 102 | |
| 103 | # freeze the axes to prevent the transform to change |
| 104 | ax0.autoscale(enable=False) |
| 105 | ax1.autoscale(enable=False) |
| 106 | |
| 107 | if ps > 0: |
| 108 | ax0.scatter(kpts0[:, 0], kpts0[:, 1], c=color, s=ps) |
| 109 | ax1.scatter(kpts1[:, 0], kpts1[:, 1], c=color, s=ps) |
| 110 | |
| 111 | |
| 112 | def add_text(idx, text, pos=(0.01, 0.99), fs=15, color='w', |
no outgoing calls
no test coverage detected