| 63 | return cv2.addWeighted(img, 1.0 - alpha, kp_mask, alpha, 0) |
| 64 | |
| 65 | def vis_mesh(img, mesh_vertex, alpha=0.5): |
| 66 | # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. |
| 67 | cmap = plt.get_cmap('rainbow') |
| 68 | colors = [cmap(i) for i in np.linspace(0, 1, len(mesh_vertex))] |
| 69 | colors = [(c[2] * 255, c[1] * 255, c[0] * 255) for c in colors] |
| 70 | |
| 71 | # Perform the drawing on a copy of the image, to allow for blending. |
| 72 | mask = np.copy(img) |
| 73 | |
| 74 | # Draw the mesh |
| 75 | for i in range(len(mesh_vertex)): |
| 76 | p = mesh_vertex[i][0].astype(np.int32), mesh_vertex[i][1].astype(np.int32) |
| 77 | cv2.circle(mask, p, radius=1, color=colors[i], thickness=-1, lineType=cv2.LINE_AA) |
| 78 | |
| 79 | # Blend the keypoints. |
| 80 | return cv2.addWeighted(img, 1.0 - alpha, mask, alpha, 0) |
| 81 | |
| 82 | def vis_3d_skeleton(kpt_3d, kpt_3d_vis, kps_lines, filename=None): |
| 83 | |