joaomlo

Problematic aug function

Mar 14th, 2022
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. usedImages = []
  2. rotations = [None, cv.ROTATE_90_CLOCKWISE, cv.ROTATE_180, cv.ROTATE_90_COUNTERCLOCKWISE]
  3.  
  4. for inputIDX in tqdm(iterable = range(NUMBER_OF_VARIANTS), desc="A Gerar",ncols=100):
  5.     r = random.SystemRandom()
  6.     placementGrid = PlacementGrid()
  7.     placementGrid.Export(str(inputIDX))
  8.  
  9.     out_image = cv.resize(random.choice(random.choice(backgrounds).images).img.copy(),(TARGET_IMAGE_DIM,TARGET_IMAGE_DIM))
  10.    
  11.     out_mask = np.zeros((TARGET_IMAGE_DIM,TARGET_IMAGE_DIM), dtype=np.uint8)
  12.     out_mask = cv.bitwise_not(out_image)
  13.    
  14.     for cell in placementGrid.squares:
  15.         r = random.SystemRandom()
  16.         pickedMaskedImage = r.choice(input)
  17.        
  18.         print("NEW CELL")
  19.         print(usedImages)
  20.         while pickedMaskedImage.image.name in usedImages:
  21.             r = random.SystemRandom()
  22.             #This r.choice is always picking the same element
  23.             #pickedMaskedImage = r.choice(input)
  24.             print(r.randint(0, len(input)-1))
  25.             pickedMaskedImage = input[r.randint(0, len(input)-1)]
  26.             #print(pickedMaskedImage.image.name)
  27.             if len(usedImages) == len(input):
  28.                 usedImages = []
  29.         usedImages.append(pickedMaskedImage.image.name)
  30.  
  31.         imageClone = pickedMaskedImage.image.img.copy()
  32.         maskClone = pickedMaskedImage.mask.img.copy()
  33.        
  34.         rotation = r.choice(rotations)
  35.         if rotation != None:
  36.             imageClone = cv.rotate(imageClone, rotation)
  37.             maskClone = cv.rotate(maskClone, rotation)
  38.  
  39.         imageClone = cv.resize(imageClone, cell.abs_size,interpolation=cv.INTER_CUBIC)
  40.         maskClone = cv.resize(maskClone, cell.abs_size,interpolation=cv.INTER_CUBIC)
  41.        
  42.         for y in range(cell.abs_size[1]):
  43.             for x in range(cell.abs_size[0]):
  44.                 out_mask[cell.cornerPoint[1] + y, cell.cornerPoint[0] + x] = maskClone[y, x]
  45.                 if maskClone[y, x] < 255:
  46.                     out_image[cell.cornerPoint[1] + y, cell.cornerPoint[0] + x] = imageClone[y, x]
  47.         print("CELL FINISHED")
  48.        
  49.     cv.imwrite(OUT_DIR+str(inputIDX)+".png", out_image)
  50.     cv.imwrite(OUT_DIR+str(inputIDX)+"_mask_.png", out_mask)
  51.     print("IMAGE WRITTEN")
Advertisement
Add Comment
Please, Sign In to add comment