help="data type [train, valid]", choices=["train", "valid"]) parser.add_argument( "-c", "--category", help="category type [date, number, all]", choices=["date", "number", "all"], default="all", ) parser.add_argument("-o", "--output", help="save result file path", default="results") args = parser.parse_args() images, anns, classes = loadAnns(args.basedir, args.target) assert len(classes) == 11, "all data annotation set should be needed" if args.category == "date": allowcatnum = [11] classes = [classes[10]] classes[0]["id"] = 1 elif args.category == "number": allowcatnum = list(range(1, 11)) classes = classes[0:10] new_anns = [] if args.category != "all": for ann in anns: if ann["category_id"] in allowcatnum: if args.category == "date":
required=True) parser.add_argument("-n", "--name", help="append name for replace image", default="d3") parser.add_argument("-t", "--target", help="data type [train, valid]", choices=["train", "valid"]) parser.add_argument("-o", "--output", help="save result file path", default="results") args = parser.parse_args() images0, anns0, classes0 = loadAnns(args.dataset0, args.target) images1, anns1, classes1 = loadAnns(args.dataset1, args.target) assert classes0 == classes1, "two dataset has different classes" imagename2imgidx = {} for idx, image1 in enumerate(images1): imagename2imgidx[image1["file_name"]] = idx imageid2annidx = {} for idx, ann1 in enumerate(anns1): if ann1["image_id"] not in imageid2annidx: imageid2annidx[ann1["image_id"]] = [] imageid2annidx[ann1["image_id"]].append(idx) os.makedirs(os.path.join(args.output, args.target), exist_ok=True)
"-o", "--output", help="save result file path", default="results" ) args = parser.parse_args() basedir = os.path.abspath(os.path.expanduser(args.basedir)) imageSizes = [(2480, 3507), (793, 1121)] std_size = (793, 1121) convertRate = {} for size in imageSizes: assert size[0] != 0 and size[1] != 0, "size should not be zero" convertRate[size[0]] = std_size[0] / size[0] for target in args.targets: imageAnns, Anns, categories = loadAnns(basedir, target) idlist = {} os.makedirs(os.path.join(args.output, target), exist_ok=True) for imageann in tqdm(imageAnns, desc=f"{target} : "): idlist[imageann["id"]] = convertRate[imageann["width"]] imageann["height"] = int( imageann["height"] * convertRate[imageann["width"]] + 0.5 ) imageann["width"] = int( imageann["width"] * convertRate[imageann["width"]] + 0.5 ) img = cv2.imread(os.path.join(basedir, target, imageann["file_name"])) img = cv2.resize(img, (imageann["width"], imageann["height"]))
for m in [(0, 3, 3, 6), (3, 6, 0, 3)]: for j in range(m[0], m[1]): move = -args.gap * 3 for k in range(0, 2): for i in range(m[2], m[3]): copymethod.append([i, j, move]) if move == -args.gap: move += args.gap * 2 else: move += args.gap os.makedirs(os.path.join(args.outdir, args.target), exist_ok=True) images, annotations, categories = loadAnns(datapath, args.target) imageid2ann = {} for ann in annotations: if ann["image_id"] not in imageid2ann: imageid2ann[ann["image_id"]] = [] imageid2ann[ann["image_id"]].append(ann) ''' sorted datebox ----------------- | | | 0 3 | | | | 1 4 | | | | 2 5 |