Exemple #1
0
def RPN_trainloader():
	# Skip ever 100 no intersection
	pos_count = 0
	for i, image_loc in enumerate(image_list):
		print("NEW IMAGE")
		name = image_loc[:image_loc.index(".")]

		cur_image = np.asarray(Image.open(os.path.join(IMAGE_DIR, image_loc)))
		bboxes = json.loads(open(os.path.join(BBOX_DIR, name + ".json"), "r").read())

		rectArr = list(map(lambda x: utils.Rectangle(int(min(x[0], x[1])),
													 int(min(x[2], x[3])),
													 int(max(x[0], x[1])),
													 int(max(x[2], x[3]))), bboxes))

		image = cur_image
		sizes = [(image.shape[1] // 15, image.shape[0] // 20), (image.shape[1] // 30, image.shape[0] // 30),
				 (image.shape[1] // 20, image.shape[0] // 15), (image.shape[1] // 30, image.shape[0] // 40)]


		for width, height in sizes:
			for window in utils.sliding_window(image, (10, 10), windowSize=(width, height)):
				curRect = utils.Rectangle(window[0], window[1], window[0] + width, window[1] + height)
				area = calculateIntersectArea(curRect, rectArr)
				ratio = area / curRect.area
				label = 0
				if ratio > .3:
					label = 1
				if ratio > .7:
					label = 2

				if label == 0:
					pos_count += 1
					if pos_count % 10 != 0:
						continue
				# print(area, curRect.area)
				# if area > 500:
				#     plt.imshow(window[2])
				#     plt.show()
				img = image_loader(Image.fromarray(window[2]))



				# pilTrans = transforms.ToPILImage()
				# pilImg = pilTrans(img.cpu())
				# plt.imshow(np.asarray(pilImg))
				# plt.show()
				yield (img, label)
Exemple #2
0
 def getTilesInCollider(self, dx=0, dy=0):
     """Calculate the grid tiles that are underneath each corner of this sprite's bounding box"""
     tiles = []
     rect = utils.Rectangle(self.collider.x + dx, self.collider.y + dy,
                            self.collider.width, self.collider.height)
     # top left
     point = rect.getTopLeft()
     point[0] >>= 4  # divide by 16
     point[1] >>= 4  # divide by 16
     if point[0] >= 0 and point[1] >= 0 and point[
             0] < GAME.tilesX and point[1] < GAME.tilesY:
         tiles.append(point)
     # top right
     point = rect.getTopRight()
     point[0] >>= 4
     point[1] >>= 4
     if (point[0] >= 0 and point[1] >= 0 and point[0] < GAME.tilesX
             and point[1] < GAME.tilesY) and not point in tiles:
         tiles.append(point)
     # bottom left
     point = rect.getBtmLeft()
     point[0] >>= 4
     point[1] >>= 4
     if (point[0] >= 0 and point[1] >= 0 and point[0] < GAME.tilesX
             and point[1] < GAME.tilesY) and not point in tiles:
         tiles.append(point)
     # bottom right
     point = rect.getBtmRight()
     point[0] >>= 4
     point[1] >>= 4
     if (point[0] >= 0 and point[1] >= 0 and point[0] < GAME.tilesX
             and point[1] < GAME.tilesY) and not point in tiles:
         tiles.append(point)
     # return list of tiles
     return tiles
Exemple #3
0
   def __init__(self, range):
      self.sensesPattern = utils.Rectangle(range, range)
      self.idToPriorityMap = {
         '_' : 0,
         '@' : 0,
         'e' : 0,
         '#' : 1,
      }

      self.seenPositions = []
Exemple #4
0
 def setDistance(self, range):
    self.sensesPattern = utils.Rectangle(range, range)
import json
import utils

with utils.rels_path.open() as f:
    image_rels = json.load(f)

with utils.flat_rels_path.open(mode='w') as f:
    first = True
    for img in image_rels:
        print("working on image %d ..." % (img['image_id']))
        for rel in img['relationships']:
            obj = rel['object']
            subj = rel['subject']
            predicate = rel['predicate']
            r_obj = utils.Rectangle(obj['x'], obj['y'], obj['w'], obj['h'])
            r_subj = utils.Rectangle(subj['x'], subj['y'], subj['w'],
                                     subj['h'])
            r = utils.SpatialRelation(r_obj, r_subj, predicate,
                                      img['image_id'])

            if first:
                f.write(r.get_header_string())
                first = False

            f.write(r.get_string())
Exemple #6
0
import Col2D
import pygame
import utils
import random
import math
import sys

pygame.init()
DISPLAY = pygame.display.set_mode((900, 900))

rect1 = utils.RegularPolygon((200, 200), 75, (0, 255, 255), 5, math.pi)
rect2 = utils.RegularPolygon((200, 200), 50, (255, 0, 255), 3, 0)

player = utils.RegularPolygon((200, 200), 50, (255, 0, 255), 3, 0)
ground = utils.Rectangle((0, 850), (900, 50), (255, 255, 255))

myfont = pygame.font.SysFont("monospace", 30)
locktomouse1 = False
locktomouse2 = False
locktomouse3 = False
offset = [0, 0]
coll = "Tech Demo"
while True:
    DISPLAY.fill((0, 0, 0))
    x, y = pygame.mouse.get_pos()
    if locktomouse1:
        rect1.updatepos((x + offset[0], y + offset[1]))
    if locktomouse2:
        rect2.updatepos((x + offset[0], y + offset[1]))
    if locktomouse3:
        player.updatepos((x + offset[0], y + offset[1]))
Exemple #7
0
import pygame, utils, Col2D

pygame.init()
screen = pygame.display.set_mode((500, 500))

player = utils.Player((0, 200), (0, 255, 0))
objects = [
    utils.Rectangle((0, 450), (500, 50), (255, 255, 0)),
    utils.Rectangle((0, 300), (500, 5), (255, 255, 0))
]
lasttick = 0
while True:
    curtick = pygame.time.get_ticks()
    dt = (curtick - lasttick) / 1000

    screen.fill((0, 0, 0))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            player.jump(objects)

    player.update(dt, objects)

    player.draw(screen)
    for obj in objects:
        obj.draw(screen)

    lasttick = curtick
Exemple #8
0
        # 					 np.abs(cur_region[1] - cur_region[0]), np.abs(cur_region[2] - cur_region[3]))
        #
        #
        cur_region = list(map(lambda x: int(x), cur_region))

        xmin = min(cur_region[0], cur_region[1])
        xmax = max(cur_region[0], cur_region[1])
        ymin = min(cur_region[2], cur_region[3])
        ymax = max(cur_region[2], cur_region[3])

        result = Image.fromarray((wantedImage[ymin:ymax,
                                              xmin:xmax]).astype(np.uint8))
        result.save(os.path.join(SAVE_POS_DIR, name + "-" + str(i) + ".png"))

        # 	save rectangle
        rectArr.append(utils.Rectangle(xmin, ymin, xmax, ymax))

    neg_count = 0
    if CREATE_NEGATIVE_IMAGES:
        width = wantedImage.shape[1] // 15
        height = wantedImage.shape[0] // 15
        for window in utils.sliding_window(wantedImage,
                                           (width // 2, height // 2),
                                           windowSize=(width, height)):
            window_rect = utils.Rectangle(window[0], window[1],
                                          window[0] + width,
                                          window[1] + height)
            valid = True
            for i in rectArr:
                if window_rect.intersects(i):
                    valid = False