Advertisement
EXTREMEXPLOIT

Data Generator

Sep 5th, 2020
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. from PIL import Image, ImageDraw, ImageFont
  2. import random, time
  3.  
  4. def GenerateImage(FileName):
  5.         IMG_MODE = "RGB"
  6.         SIZE_X, SIZE_Y = 150, 150
  7.         IMG_SIZE = (SIZE_X, SIZE_Y)
  8.         r = lambda: random.randint(0,255)
  9.         IMG_COLOR = '#%02X%02X%02X' % (r(),r(),r())
  10.         RECTANGLE_COLOR = '#%02X%02X%02X' % (r(),r(),r())
  11.         IMG_NAME = str(FileName) + str(".jpg")
  12.         IMG = Image.new(IMG_MODE, IMG_SIZE, IMG_COLOR)
  13.         Draw = ImageDraw.Draw(IMG)
  14.         Shape = [random.randint(0, SIZE_X), random.randint(0, SIZE_Y), random.randint(0, SIZE_X), random.randint(0, SIZE_Y)]
  15.         XSize, YSize = Shape[2] - Shape[0], Shape[3] - Shape[1]
  16.         LeftPoint = Shape[0], Shape[1]
  17.         Draw.rectangle(Shape, fill=RECTANGLE_COLOR, outline=RECTANGLE_COLOR)
  18.         IMG.save(IMG_NAME)
  19.         return LeftPoint, XSize, YSize
  20.  
  21. csvFile = open('./DATA/Y_TEST/Rectangles.csv', 'w')
  22. csvFile.write('LeftPoint[0],LeftPoint[1],XSize,YSize\n')
  23. for ImageID in range(100):
  24.     LeftPoint, XSize, YSize = GenerateImage(f'./DATA/X_TEST/{ImageID}')
  25.     csvFile.write(f'{LeftPoint[0]},{LeftPoint[1]},{XSize},{YSize}\n')
  26.  
  27.  
  28. csvFile = open('./DATA/Y_TRAIN/Rectangles.csv', 'w')
  29. csvFile.write('LeftPoint[0],LeftPoint[1],XSize,YSize\n')
  30. for ImageID in range(1000):
  31.     LeftPoint, XSize, YSize = GenerateImage(f'./DATA/X_TRAIN/{ImageID}')
  32.     csvFile.write(f'{LeftPoint[0]},{LeftPoint[1]},{XSize},{YSize}\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement