Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- usedImages = []
- rotations = [None, cv.ROTATE_90_CLOCKWISE, cv.ROTATE_180, cv.ROTATE_90_COUNTERCLOCKWISE]
- for inputIDX in tqdm(iterable = range(NUMBER_OF_VARIANTS), desc="A Gerar",ncols=100):
- r = random.SystemRandom()
- placementGrid = PlacementGrid()
- placementGrid.Export(str(inputIDX))
- out_image = cv.resize(random.choice(random.choice(backgrounds).images).img.copy(),(TARGET_IMAGE_DIM,TARGET_IMAGE_DIM))
- out_mask = np.zeros((TARGET_IMAGE_DIM,TARGET_IMAGE_DIM), dtype=np.uint8)
- out_mask = cv.bitwise_not(out_image)
- for cell in placementGrid.squares:
- r = random.SystemRandom()
- pickedMaskedImage = r.choice(input)
- print("NEW CELL")
- print(usedImages)
- while pickedMaskedImage.image.name in usedImages:
- r = random.SystemRandom()
- #This r.choice is always picking the same element
- #pickedMaskedImage = r.choice(input)
- print(r.randint(0, len(input)-1))
- pickedMaskedImage = input[r.randint(0, len(input)-1)]
- #print(pickedMaskedImage.image.name)
- if len(usedImages) == len(input):
- usedImages = []
- usedImages.append(pickedMaskedImage.image.name)
- imageClone = pickedMaskedImage.image.img.copy()
- maskClone = pickedMaskedImage.mask.img.copy()
- rotation = r.choice(rotations)
- if rotation != None:
- imageClone = cv.rotate(imageClone, rotation)
- maskClone = cv.rotate(maskClone, rotation)
- imageClone = cv.resize(imageClone, cell.abs_size,interpolation=cv.INTER_CUBIC)
- maskClone = cv.resize(maskClone, cell.abs_size,interpolation=cv.INTER_CUBIC)
- for y in range(cell.abs_size[1]):
- for x in range(cell.abs_size[0]):
- out_mask[cell.cornerPoint[1] + y, cell.cornerPoint[0] + x] = maskClone[y, x]
- if maskClone[y, x] < 255:
- out_image[cell.cornerPoint[1] + y, cell.cornerPoint[0] + x] = imageClone[y, x]
- print("CELL FINISHED")
- cv.imwrite(OUT_DIR+str(inputIDX)+".png", out_image)
- cv.imwrite(OUT_DIR+str(inputIDX)+"_mask_.png", out_mask)
- print("IMAGE WRITTEN")
Advertisement
Add Comment
Please, Sign In to add comment