def show_keypoint(imgDir, img, anns): im = cv2.imread(imgDir + img['file_name']) flip = np.random.choice([True, False]) scale = np.random.uniform(0.8, 1.0, 1)[0] flip = False scale = 1 im = cv2.resize(im, (0, 0), fx=scale, fy=scale) print("keypoint flip: {}, keypoint scale: {}".format(flip, scale)) if flip: im = cv2.flip(im, 1) for ann in anns: vis_list = range(2, 3*4, 3) keypoint = [p for idx, p in enumerate(ann['keypoints']) if idx not in vis_list] keypoint = np.array(keypoint) # keypoint = pointobb_rescale(keypoint, scale, reverse_flag=False) if flip: img_shape = im.shape keypoint = pointobb_flip(keypoint, img_shape) for idx in range(4): if idx == 0: color = (0, 0, 255) else: color = (255, 0, 0) # color = (255, 153, 102) cv2.circle(im, (int(keypoint[2 * idx]), int(keypoint[2 * idx + 1])), 5, color, -1) # color = (255, 153, 102) # im = draw_rectangle_by_points(im, keypoint, color=color) cv2.imwrite('1.jpg', im) cv2.imshow('demo', im) cv2.waitKey(10000)
def show_pointobb(imgDir, img, anns): im = cv2.imread(imgDir + img['file_name']) flip = np.random.choice([True, False]) scale = np.random.uniform(0.8, 1.0, 1)[0] flip = False scale = 1 im = cv2.resize(im, (0, 0), fx=scale, fy=scale) print("pointobb flip: {}, pointobb scale: {}".format(flip, scale)) if flip: im = cv2.flip(im, 1) for ann in anns: pointobb = ann['pointobb'] pointobb = np.array(pointobb) pointobb = pointobb_rescale(pointobb, scale, reverse_flag=False) if flip: img_shape = im.shape pointobb = pointobb_flip(pointobb, img_shape) # for idx in range(4): # if idx == 0: # color = (0, 0, 255) # else: # color = (255, 0, 0) # # color = (255, 153, 102) # color = (75, 25, 230) # cv2.circle(im, (int(pointobb[2 * idx]), int(pointobb[2 * idx + 1])), 5, color, -1) # color = (255, 153, 102) color = (75, 25, 230) im = draw_rectangle_by_points(im, pointobb, color=color) cv2.imwrite('1.jpg', im) cv2.imshow('demo', im) cv2.waitKey(10000)