Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image, ImageDraw, ImageFont
- import random, time
- def GenerateImage(FileName):
- IMG_MODE = "RGB"
- SIZE_X, SIZE_Y = 150, 150
- IMG_SIZE = (SIZE_X, SIZE_Y)
- r = lambda: random.randint(0,255)
- IMG_COLOR = '#%02X%02X%02X' % (r(),r(),r())
- RECTANGLE_COLOR = '#%02X%02X%02X' % (r(),r(),r())
- IMG_NAME = str(FileName) + str(".jpg")
- IMG = Image.new(IMG_MODE, IMG_SIZE, IMG_COLOR)
- Draw = ImageDraw.Draw(IMG)
- Shape = [random.randint(0, SIZE_X), random.randint(0, SIZE_Y), random.randint(0, SIZE_X), random.randint(0, SIZE_Y)]
- XSize, YSize = Shape[2] - Shape[0], Shape[3] - Shape[1]
- LeftPoint = Shape[0], Shape[1]
- Draw.rectangle(Shape, fill=RECTANGLE_COLOR, outline=RECTANGLE_COLOR)
- IMG.save(IMG_NAME)
- return LeftPoint, XSize, YSize
- csvFile = open('./DATA/Y_TEST/Rectangles.csv', 'w')
- csvFile.write('LeftPoint[0],LeftPoint[1],XSize,YSize\n')
- for ImageID in range(100):
- LeftPoint, XSize, YSize = GenerateImage(f'./DATA/X_TEST/{ImageID}')
- csvFile.write(f'{LeftPoint[0]},{LeftPoint[1]},{XSize},{YSize}\n')
- csvFile = open('./DATA/Y_TRAIN/Rectangles.csv', 'w')
- csvFile.write('LeftPoint[0],LeftPoint[1],XSize,YSize\n')
- for ImageID in range(1000):
- LeftPoint, XSize, YSize = GenerateImage(f'./DATA/X_TRAIN/{ImageID}')
- csvFile.write(f'{LeftPoint[0]},{LeftPoint[1]},{XSize},{YSize}\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement