def all_resources_preparation(self): path_to_cvat_data = self.path_to_cvat_data #target_path = self.background_target_path cvat_data = CvatDataset() cvat_data.load(path_to_cvat_data) image_ids = cvat_data.get_image_ids() polygons = [] points = [] image_sizes = [] image_names = [] for idx, image in enumerate(image_ids): polygons.append(cvat_data.get_polygons(image)) points.append(cvat_data.get_points(image)) image_sizes.append(cvat_data.get_size(image)) image_names.append(cvat_data.get_name(image)) points_list = points[idx] image_size = image_sizes[idx] image_name = image_names[idx] # background creation self.background_alignment(points_list=points_list, image_size=image_size, image_name=image_name) # cars cropping car_polygons = polygons[idx] self.cars_cropping(car_polygons=car_polygons, image_name=image_name) print(image_ids)
def main(args): global output_CvatDataset global input_CvatDataset input_CvatDataset = CvatDataset() input_CvatDataset.load(args.input_file) output_CvatDataset = CvatDataset() list_of_polygons = points_please() get_polygons(list_of_polygons) dump(args.output_file)
def points_please(input_file): ds = CvatDataset() ds.load(input_file) polygons = list() all_polygons = list() for image_id in ds.get_image_ids(): for polygon in ds.get_polygons(image_id): label = label_image(polygon["label"].replace("_", ".")) polygons += [polygon["points"]] for i in range(len(polygons)): for j in range(len(polygons[i])): polygons[i][j] = tuple(polygons[i][j]) all_polygons.append(polygons) polygons = list() return all_polygons
def main(args): ds = CvatDataset() ds.load(args.input_file) for file in os.listdir(args.output_folder): file_path = os.path.join(args.output_folder, file) if os.path.isfile(file_path): os.unlink(file_path) for image_id in tqdm(ds.get_image_ids()): f = open(args.output_folder+"/" + str(image_id) + '.txt', 'w') polygons = ds.get_polygons(image_id) for polygon in polygons: box = polygon_to_box(polygon["points"]) box["label"] = polygon["label"] write_file(f, box) boxes = ds.get_boxes(image_id) for box in boxes: write_file(f, box) f.close()
def main(args): ds = CvatDataset() ds.load(args.annot_xml) result = [] for image_id in tqdm(ds.get_image_ids()): filename = "{:0>6}".format(image_id) boxes = ds.get_boxes(image_id) for box in boxes: label = box["label"].replace("_", ".") occluded = box["occluded"] record = {k: int(box[k]) for k in ["xtl", "ytl", "xbr", "ybr"]} record["frame"] = int(os.path.join("", filename)) record["class"] = label record["occluded"] = occluded result.append(record) df = pd.DataFrame( result, columns=["frame", "occluded", "xtl", "ytl", "xbr", "ybr", "class"]) polygons(df)