Exemplo 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
Exemplo 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
Exemplo n.º 3
0
def FP(x1, thetas, example_no=[], singleton=False):
    x = deepcopy(x1)

    # offsetting the history to keep in norm with the labeling
    activation_history = [[]]

    # adding inital bias unit
    if singleton:
        x.insert(0, 1)
    else:
        x[0].insert(0, 1)

    # inital seperating
    if not singleton:
        yi_s = x[-1]
        x = x[0]

    activation_history.append(x)
    count_layer = 1
    for i in thetas[1:]:
        temp_ans = []
        # iterating through the
        count_node = 0
        for j in i:
            # skip bias unit calculation (effective speed up)
            if not count_node:
                count_node += 1
                continue
            # adding activation unit
            temp_ans.append(helper.h(j, x))
            count_node += 1

        # adding the bias unit for the next run
        temp_ans.insert(0, 1)
        x = temp_ans
        activation_history.append(x)
        count_layer += 1

    if singleton:
        return activation_history[-1][1:]
    return activation_history, [
        i - j for i, j in zip(activation_history[-1][1:], yi_s)
    ]
Exemplo n.º 4
0
def add(a, b=1):
    return time.time() + b + h(b)
Exemplo n.º 5
0
 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
             theta += thetaShift
         # changes object rotation if no valid placement is available at any angle
         if (currentTheta > 720):
             currentTheta = 0
             reRotate = True