def ann_to_txt(ann): out_str = '' for bbox, label in zip(ann['bboxes'], ann['labels']): poly = rbox2poly_single(bbox) str_line = '{} {} {} {} {} {} {} {} {} {}\n'.format( poly[0], poly[1], poly[2], poly[3], poly[4], poly[5], poly[6], poly[7], label, '0') out_str += str_line for bbox, label in zip(ann['bboxes_ignore'], ann['labels_ignore']): poly = rbox2poly_single(bbox) str_line = '{} {} {} {} {} {} {} {} {} {}\n'.format( poly[0], poly[1], poly[2], poly[3], poly[4], poly[5], poly[6], poly[7], label, '1') out_str += str_line return out_str
def showAnns(img, rboxes): plt.imshow(img) plt.axis('off') ax = plt.gca() ax.set_autoscale_on(False) polygons = [] color = [] circles = [] r = 5 for rbox in rboxes: c = (np.random.random((1, 3)) * 0.6 + 0.4).tolist()[0] pts = rbox2poly_single(rbox) poly = [(pts[0], pts[1]), (pts[2], pts[3]), (pts[4], pts[5]), (pts[6], pts[7])] polygons.append(Polygon(poly)) color.append(c) point = poly[0] circle = Circle((point[0], point[1]), r) circles.append(circle) p = PatchCollection(polygons, facecolors=color, linewidths=0, alpha=0.4) ax.add_collection(p) p = PatchCollection(polygons, facecolors='none', edgecolors=color, linewidths=2) ax.add_collection(p) p = PatchCollection(circles, facecolors='red') ax.add_collection(p) plt.imshow(img) plt.show()
def drow_box_on_image(img_name, bboxes): img = cv2.imdecode(np.fromfile(img_name, dtype=np.uint8), -1) for box in bboxes: box = rbox2poly_single(box) box = np.int32(np.array(box).reshape((-1, 2))) cv2.polylines(img, [box], True, (0, 255, 255)) pts = box cv2.circle(img, (pts[0][0], pts[0][1]), 2, (0, 0, 255), 0) cv2.circle(img, (pts[1][0], pts[1][1]), 4, (0, 0, 255), 0) cv2.circle(img, (pts[2][0], pts[2][1]), 6, (0, 0, 255), 0) cv2.circle(img, (pts[3][0], pts[3][1]), 8, (0, 0, 255), 0) cv2.imwrite('1.jpg', img)
def DOTAtxt2GT_to_eval(GT_xml_path, txt_dir_h, file_ext='.txt'): if not os.path.exists(txt_dir_h): os.mkdir(txt_dir_h) file_paths = GetFileFromThisRootDir(GT_xml_path, file_ext) for count, txt_path in enumerate(file_paths): bboxes, labels, bboxes_ignore, labels_ignore = parse_ann_info(txt_path) # eval txt # Task1 # write_handle_h = open( os.path.join( txt_dir_h, 'Task1_gt_{}.txt'.format( os.path.splitext(os.path.split(txt_path)[1])[0])), 'w') #Task1_gt_ for i, rbox in enumerate(bboxes): # rbox[4]=0 # rbox_cv=rotate_rect2cv(rbox) # rect_box = cv2.boxPoints(rbox_cv) rect_box = rbox2poly_single(rbox) command = '%.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %s 0\n' % ( rect_box[0], rect_box[1], rect_box[2], rect_box[3], rect_box[4], rect_box[5], rect_box[6], rect_box[7], labels[i]) write_handle_h.write(command) write_handle_h.close()