def polygons(df_file): df = pd.DataFrame( columns=["frame", "occluded", "xtl", "ytl", "xbr", "ybr", "class"]) ds = CvatDataset() frames = df_file["frame"] frames = list(set(frames)) frames.sort() for frame in frames: df = df_file.loc[df_file.frame == frame] ds.add_image(frame) for record in df.to_dict("records"): label = list(map(label_image, [record["class"]]))[0] if label == "round": ds.add_polygon(image_id=frame, points=polygon_round(record["xtl"], record["ytl"], record["xbr"], record["ybr"]), label=record["class"], occluded=int(record["occluded"])) elif label == "rhombus": ds.add_polygon(image_id=frame, points=polygon_rhombus(record["xtl"], record["ytl"], record["xbr"], record["ybr"]), label=record["class"], occluded=int(record["occluded"])) elif label == "triangle": ds.add_polygon(image_id=frame, points=polygon_triangle(record["xtl"], record["ytl"], record["xbr"], record["ybr"]), label=record["class"], occluded=int(record["occluded"])) elif label == "reverse_triangle": ds.add_polygon(image_id=frame, points=polygon_reverse_triangle( record["xtl"], record["ytl"], record["xbr"], record["ybr"]), label=record["class"], occluded=int(record["occluded"])) else: ds.add_box(image_id=frame, xtl=record["xtl"], ytl=record["ytl"], xbr=record["xbr"], ybr=record["ybr"], label=record["class"], occluded=int(record["occluded"])) ds.dump(args.output_file)
def dump(polygons, output_file): ds = CvatDataset() image_id = 0 for POINTS in polygons: ds.add_image(image_id) for points in POINTS: ds.add_polygon( image_id=image_id, points=points, label="car", occluded=0) image_id += 1 print(image_id) ds.dump(output_file)