[docs]defdraw_points(img:np.ndarray,pts:np.ndarray,colors:Optional[np.ndarray]=None,radius=1,order="uv",)->np.ndarray:""" Args: img (ndarray): original image pts (ndarray): points, shaped (n x 2) or (2) colors (ndarray): color, shaped (n x 3) or (3) radius (int): radius of points order (str): order of points, "uv" or "xy", default "uv" (since most keypoints dataset use uv order) """assertorderin["xy","uv"],"order should be xy or uv"ifcolorsisNone:colors=np.asarray(COMMON_COLOR["red"])pts,colors=np.asarray(pts),np.asarray(colors)assert(pts.ndim==1orpts.ndim==2)andpts.shape[-1]==2,f"wrong pts shape: {pts.shape}"assert(colors.ndim==1orcolors.ndim==2)andcolors.shape[-1]in[3,4],f"wrong colors shape: {colors.shape}"ifpts.ndim==1:pts=pts[None,:]ifcolors.ndim==2:assertcolors.shape[0]==pts.shape[0],"colors and pts should in the same number"iforder=="xy":pts=pts[:,::-1]vis_img=img.copy()# avoid modifying the original imagepts=pts.astype(int)# round to intforiinrange(pts.shape[0]):# opencv use the uv ordercolor=colorsifcolors.ndim==1elsecolors[i]cv2.circle(vis_img,center=tuple(pts[i].tolist()),color=tuple(color.tolist()),radius=radius,thickness=-1,)returnvis_img