Ejemplo n.º 1
0
def makeImg(images):
    obstacles = []
    background = Image.open("back.png")
    # radius for checking if objects are inside circle and positioning center
    radius = 180
    # x from 0 to 310; y from 155 - sqrt(-(x-310)x) to 155 + sqrt(-(x-310)x)
    x = np.random.normal(radius, (radius/goalVariance)/3)
    yRadius = math.sqrt(-1 * x * (x - radius * 2))
    y = np.random.normal(radius, (yRadius)/3)
    for i in range(1, 5):
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "obj" + str(images[j]) + ".png"
        images.pop(j)
        obj = Image.open(name)
        objX = x
        objY = y
        # splits objects into four quadrants around point
        if (i % 2 == 0):
            objX -= w(obj)
        if (i > 2):
            objY -= h(obj)
        z = Rectangle(objX, w(obj), objY, h(obj))
        foundLoc = (not z.hasCollision(obstacles)) and z.insideCircle(radius, radius, radius)
        if not foundLoc:
            return None
        else:
            pasteOn(background, obj, objX, objY)
        obstacles.append(z)
    return background
Ejemplo n.º 2
0
def makeImg(images):
    gripper = Rectangle(295, 125, 120, 125)
    obstacles = [gripper]
    # grip = Image.new('RGB', (125,125), color=400)
    # white background
    clusterBack = Image.open("scripts/objects/back.png")
    # background of result
    background = Image.open("scripts/objects/" + backName + ".png")
    # radius for checking if objects are inside circle and positioning center
    radius = 180 # 180
    xCenter = 160
    yRadius = 210
    yCenter = 210
    # x from 0 to 310; y from 155 - sqrt(-(x-310)x) to 155 + sqrt(-(x-310)x)
    x = np.random.normal(xCenter, (radius*1.2))
    # print (radius/2), yRadius/2
    # field = Image.new('RGB', (int(radius*1.2),int(yRadius*1.2)), color=400)
    # yRadius = math.sqrt(-1 * x * (x - radius * 2))
    y = np.random.normal(yCenter, (yRadius*1.2))
    center = (x,y)
    order = []
    for i in range(1, 5):
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "scripts/objects/" + "obj" + str(images[j]) + ".png"
        order.append(images[j])
        images.pop(j)
        obj = Image.open(name)
        objX = x
        objY = y
        # splits objects into four quadrants around point
        if (i % 2 == 0):
            objX -= w(obj)
        if (i > 2):
            objY -= h(obj)
        z = Rectangle(objX, w(obj), objY, h(obj))
        # foundLoc = (not z.hasCollision(obstacles)) and z.insideCircle(radius, radius, radius)
        foundLoc = (not z.hasCollision(obstacles) and z.insideRectangle((0, 2*yRadius), (2*radius,0)))
        if not foundLoc:
            # print "Failed: ", (x,y)
            return None, None, order
        else:
            pasteOn(clusterBack, obj, objX, objY)
        obstacles.append(z)
    # Random angle from -30 to 30; noise
    theta = (random.random() * 60) - 30
    clusterBack = clusterBack.rotate(theta)
    clusterBack = makeTransparent(clusterBack)
    # pasteOn(background, field, xCenter - int(radius/2*1.2), yCenter- int(yRadius/2*1.2))
    # pasteOn(background, field, 0, 0)
    pasteOn(background, clusterBack, 0, 0)
    return background, center, order
Ejemplo n.º 3
0
 rotLimit = 40
 rObj = obj.rotate(getRot(rotLimit), Image.NEAREST, True)
 foundLoc = False
 reRotate = False
 # iterates to find valid placement for current object
 while (not foundLoc):
     # increases rotation of object if it did not fit
     if (reRotate):
         rotLimit += 20
         rObj = obj.rotate(getRot(rotLimit), Image.NEAREST, True)
         reRotate = False
     # avoid infinite loops
     if (rotLimit > 700):
         foundLoc = True
     hasSpace = True
     radialD = w(goal)/2
     # iterates distance from goal to find valid placement at current angle
     while (not foundLoc and hasSpace):
         objx = gObj.cenX + radialD * cosine(theta)
         objy = gObj.cenY + radialD * sine(theta)
         z = Rectangle(objx, w(rObj), objy, h(rObj))
         foundLoc = not z.hasCollision(obstacles)
         hasSpace = z.insideCircle(trueRadius, trueRadius, trueRadius)
         foundLoc = foundLoc and hasSpace
         radialD += 5
         if (foundLoc):
             pasteOn(background, rObj, objx, objy)
             obstacles.append(z)
         # change angle if no valid placement is available at current angle
         elif (not hasSpace):
             currentTheta += thetaShift