Skip to content

Instantly share code, notes, and snippets.

@wroscoe
Last active May 6, 2018 04:46
Show Gist options
  • Save wroscoe/bd231bfc839694237e9e0d311327eae9 to your computer and use it in GitHub Desktop.
Save wroscoe/bd231bfc839694237e9e0d311327eae9 to your computer and use it in GitHub Desktop.
draw rectangles ("people") using Augmentor
import Augmentor
from Augmentor.Operations import Operation
class GeneratePeopleShapes(Augmentor.Operations.Operation):
def __init__(self, probability):
Operation.__init__(self, probability)
@staticmethod
def gen_random_rectangle_coords(top, bottom, left, right):
width =random.randint(5, 59)
height = random.randint(30,60)
x_center = random.randint(left, right)
y_center = random.randint(top, bottom)
tl = (x_center-width, y_center+height)
br = (x_center+width, y_center-height)
return tl, br
def perform_operation(self, images):
def do(image):
arr = np.array(image)
tl, br = self.gen_random_rectangle_coords(10, 30, 10, 150)
color = tuple(random.choice(range(0, 100)) for i in range(3))
arr = cv2.rectangle(arr, tl, br, color,-1)
image = Image.fromarray(arr)
return image
augmented_images = []
for image in images:
augmented_images.append(do(image))
return augmented_images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment