示例#1
0
def get_current_hp(frame):
    hp_img = im.get_hp_img(frame, hp_bar_template)
    hp_img = im.process_hp_bar(hp_img)

    hp_value = im.read_image(hp_img)

    return hp_value, hp_img
示例#2
0
def is_game_over_screen(frame):
    death_message = im.get_death_screen_area(frame)
    death_message_hist = im.get_image_hist(death_message)

    if im.hist_similarity(death_message_hist, death_message_asset_hist) >= .9:
        return True
    return False
示例#3
0
def is_level_up_screen(frame):
    lvl_up_text_image = im.get_lvl_up_text_image(frame)
    lvl_up_hist = im.get_image_hist(lvl_up_text_image)

    if im.hist_similarity(lvl_up_hist, lvl_up_template_hist) >= .9:
        return True
    return False
示例#4
0
 def exitGame(self):
     ImageManager.unloadSet("debug")
     AudioManager.unloadSfxSet("debug")
     World.cleanupCompletely()
     Globals.PLAYER = None
     pygame.mixer.music.fadeout(1000)
     if Globals.CURRENT_LEVEL == "one":
         Globals.CURRENT_LEVEL = "two"
         if Globals.LEVELS_BEAT < 1:
             Globals.LEVELS_BEAT = 1
     elif Globals.CURRENT_LEVEL == "two":
         Globals.CURRENT_LEVEL = "three"
         if Globals.LEVELS_BEAT < 2:
             Globals.LEVELS_BEAT = 2
     elif Globals.CURRENT_LEVEL == "three":
         Globals.CURRENT_LEVEL = "four"
         if Globals.LEVELS_BEAT < 3:
             Globals.LEVELS_BEAT = 3
     elif Globals.CURRENT_LEVEL == "four":
         Globals.CURRENT_LEVEL = "five"
         if Globals.LEVELS_BEAT < 4:
             Globals.LEVELS_BEAT = 4
     Globals.MINI_SUNS_INLVL = 0
     Globals.STATE = WinScreen.WinScreen()
     Globals.CHECKPOINT_SET = False
 def __init__(self):
     self.time = 0.0
     self.color = pygame.color.Color("white")
     AudioManager.loadSfxSet("title")
     ImageManager.loadSet("cutscene")
     self.temp = ImageManager.levelRes["cutscene"]["YOUWIN.png"]
     self.state = 0
     self.sceneTime = 0.0
示例#6
0
 def __init__(self, level):
     ImageManager.loadSet(level)
     if "Layer0.png" in ImageManager.levelRes[level]:
         self.bg0 = ImageManager.levelRes[level]["Layer0.png"]
     if "Layer1.png" in ImageManager.levelRes[level]:
         self.bg1 = ImageManager.levelRes[level]["Layer1.png"]
     if "Layer2.png" in ImageManager.levelRes[level]:
         self.bg2 = ImageManager.levelRes[level]["Layer2.png"]
     if "Layer3.png" in ImageManager.levelRes[level]:
         self.bg3 = ImageManager.levelRes[level]["Layer3.png"]
示例#7
0
    def download_image_thread(self):

        if not os.path.exists(self.image_dir + self.image_info["image_id"]):

            header = {
                'User-Agent':
                'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'
            }

            try:

                self.image_info[
                    "image_path"] = self.image_dir + self.image_info["image_id"]
                req = urllib2.Request(self.image_info["image_url"],
                                      headers=header)
                res = urllib2.urlopen(req)
                f = open(self.image_dir + self.image_info["image_id"], "wb")
                f.write(res.read())
                f.close()

                if self.image_info["custom_frame"] or self.image_info[
                        "force_label"]:
                    ImageManager.create_banner(
                        self.image_dir + self.image_info["image_id"],
                        self.image_info["x"], self.image_info["y"],
                        self.image_info["name"],
                        self.image_info["custom_frame"],
                        self.image_info["image_path"])

            except Exception as e:

                output_file = self.image_info["image_path"]
                self.image_info[
                    "image_path"] = "/usr/share/icons/Vibrancy-Colors/status/96/image-missing.png"
                image = Gtk.Image.new_from_file(self.image_info["image_path"])

                if self.image_info["video_url"] != None:
                    self.image_info[
                        "image_path"] = "/usr/share/lliurex-store/lliurex-store-gui/rsrc/icons/clean_icons/video.svg"
                else:
                    self.image_info["custom_frame"] = True
                    self.image_info["force_label"] = True

                ret = ImageManager.create_banner(
                    self.image_info["image_path"], self.image_info["x"],
                    self.image_info["y"], self.image_info["name"],
                    self.image_info["custom_frame"])
                self.image_info["pixbuf"] = ret[1].get_pixbuf()
                self.set_from_pixbuf(self.image_info)

        else:
            self.image_info[
                "image_path"] = self.image_dir + self.image_info["image_id"]

        return True
示例#8
0
def is_gameplay_screen(frame):
    gameplay_check = im.get_gameplay_check_area(frame)
    gameplay_check_hist = im.get_image_hist(gameplay_check)

    # print(im.hist_similarity(gameplay_check_hist, gameplay_check_asset_hist))

    if im.hist_similarity(gameplay_check_hist,
                          gameplay_check_asset_hist) >= .93:
        return True

    return False
示例#9
0
 def exitFinal(self):
     ImageManager.unloadSet("debug")
     AudioManager.unloadSfxSet("debug")
     World.cleanupCompletely()
     AudioManager.loadMusic("title")
     pygame.mixer.music.play(-1)
     if Globals.LEVELS_BEAT < 5:
         Globals.LEVELS_BEAT = 5
     Globals.SCORE = Globals.SCORE + 5000*Globals.MINI_SUNS
     Globals.PLAYER = None
     Globals.STATE = CompletedGameScreen.CompletedGameScreen()
     Globals.CHECKPOINT_SET = False
示例#10
0
    def open(self):
        fileName = QtGui.QFileDialog.getOpenFileName(self)
        if fileName:
            with open(str(fileName)) as fp:
                jsondict = json.load(fp)

                self.im = ImageManager(jsondict)
                for i in range(self.im.image_num):
                    self.createSubImageViewer(self.im.images[i].id,
                                              self.im.images[i].pixmap,
                                              self.im.images[i].labeled_pixels,
                                              self.im.label_colors)
示例#11
0
def restart(imagedir, seeddir):
    #delete all of the images
    print("Deleting images in the " + imagedir + " directory.")
    print("Copying images in the " + seeddir + " directory to the " +
          imagedir + " directory.")
    cont = input("Continue (y/n)? ")
    cont = cont.lower()
    if (cont != "y" and cont != "yes"):
        print("Aborting restart\n")
        sys.exit(0)
    imageman = ImageManager(imagedir, seeddir)
    imageman.restart()
示例#12
0
def N_way_one_shot_learning(N, df, items_per_class):
    """
	N:		N-1 different classes, only one example
	df:		dataframe used to load the data
	items_per_class:number of items belonging to the same class inside the dataframe
	
	return:	feature_list:	list of N different classes with only one example
			target_list:	list of correct answers (0=different, 1=same)
	"""

    feature_list = []
    target_list = []

    #	randomly choose a class among all of the classes inside the dataframe
    rnd = np.random.choice(range(0, len(df)))
    img_class = int(math.modf(rnd / items_per_class)[1])

    #	randomly choose an image within that class
    rnd1 = np.random.choice(
        range(img_class * items_per_class,
              (img_class * items_per_class) + items_per_class),
        replace=False)
    #	randomly choose another image belonging to the same class as only one example
    rnd2 = np.random.choice(
        range(img_class * items_per_class,
              (img_class * items_per_class) + items_per_class),
        replace=False)

    #	load the images
    img1 = im.load_image(df.iloc[rnd1]["path"])
    img2 = im.load_image(df.iloc[rnd2]["path"])

    #	add in X_list the image generated by overlapping the two images belonging to the same class
    feature_list.append([im.process_images(img1, img2)])
    target_list.append(1)

    #	add other N-1 different images belonging to different classes
    for j in range(0, N - 1):
        #	randomly choose a class that is different from the one previously computed
        rnd3 = np.random.choice(np.setdiff1d(
            range(0, len(df)),
            range(img_class * items_per_class,
                  (img_class * items_per_class) + items_per_class)),
                                replace=False)

        #	load the image
        img3 = im.load_image(df.iloc[rnd3]["path"])

        #	add the image generated by overlapping the two images belonging to different classes
        feature_list.append([im.process_images(img1, img3)])
        target_list.append(0)

    return feature_list, target_list
示例#13
0
 def __init__(self):
     self.time = 0.0
     self.color = pygame.color.Color("black")
     self.selectedColor = pygame.color.Color("black")
     Globals.SCREEN.fill(pygame.color.Color("black"))
     #self.selectionID = 0
     self.currentLevel()
     AudioManager.loadSfxSet("menu")
     ImageManager.loadSet("map")
     self.temp =\
         ImageManager.levelRes["map"]["Astoria_Map_Grass_aftersnowboss.png"]
     ImageManager.levelRes["map"]["Astoria_Map_Grass_aftersnowboss.png"] =\
         pygame.transform.scale(self.temp, (800, 600))
示例#14
0
 def __init__(self):
     self.time = 0.0
     self.color = pygame.color.Color("black")
     Globals.SCREEN.fill(pygame.color.Color("black"))
     self.text = "Noel's Journey ... "
     self.width, self.height = Globals.FONT.size(self.text)
     AudioManager.loadSfxSet("title")
     if AudioManager.loadedMusic != "title" or\
             not pygame.mixer.music.get_busy():
         AudioManager.loadMusic("title")
         pygame.mixer.music.play(-1)
     ImageManager.loadSet("title")
     self.temp = ImageManager.levelRes["title"]["Title_Screen.png"]
     ImageManager.levelRes["title"]["Title_Screen.png"] =\
         pygame.transform.scale(self.temp, (1000, 600))
 def __init__(self):
     self.time = 0.0
     self.color = pygame.color.Color("white")
     Globals.SCREEN.fill(pygame.color.Color("black"))
     self.text = ""
     self.width, self.height = Globals.FONT.size(self.text)
     AudioManager.loadSfxSet("title")
     if AudioManager.loadedMusic != "title" or\
             not pygame.mixer.music.get_busy():
         AudioManager.loadMusic("title")
         pygame.mixer.music.play(-1)
     ImageManager.loadSet("cutscene")
     self.temp = ImageManager.levelRes["cutscene"]["CutSceneSnowboss.png"]
     ImageManager.levelRes["cutscene"]["CutSceneSnowboss.png"] =\
         pygame.transform.scale(self.temp, (800, 600))
示例#16
0
 def __init__(self):
     self.time = 0.0
     self.color = pygame.color.Color("black")
     Globals.SCREEN.fill(pygame.color.Color("black"))
     self.temp = pygame.Surface((1, 1))
     self.text = "Gyration Games"
     self.width, self.height = Globals.FONT.size(self.text)
     self.FADEIN = True
     self.GGames = True
     self.soundPlaying = False
     AudioManager.loadSfxSet("title")
     ImageManager.loadSet("map")
     self.temp2 =\
         ImageManager.levelRes["map"]["Astoria_Map_Grass_aftersnowboss.png"]
     ImageManager.levelRes["map"]["Astoria_Map_Grass_aftersnowboss.png"] =\
         pygame.transform.scale(self.temp2, (800, 600))
示例#17
0
文件: tumblr.py 项目: eiurur/NNNNN
 def categorize(self, post):
     return [
         CategorizeResult(url=photo["original_size"]["url"],
                          filename=ImageManager.get_remote_md5_sum(
                              photo["original_size"]["url"]))
         for idx, photo in enumerate(post["photos"])
     ]
示例#18
0
    def set_from_pixbuf(self, image_info):

        self.set_image_info(image_info)

        x = self.image_info["x"]
        y = self.image_info["x"]
        pixbuf = self.image_info["pixbuf"]
        aspect_ratio = self.image_info["aspect_ratio"]

        if pixbuf != None:

            if x == -1 and y == -1:

                self.image.set_from_pixbuf(pixbuf)
                self.image_info["x"] = pixbuf.get_width()
                self.image_info["y"] = pixbuf.get_height()
                self.set_visible_child_name("image")

            else:

                pixbuf = ImageManager.scale_pixbuf(pixbuf, x, y, aspect_ratio)
                self.image.set_from_pixbuf(pixbuf)
                self.image_info["x"] = pixbuf.get_width()
                self.image_info["y"] = pixbuf.get_height()
                self.set_visible_child_name("image")

            return True

        return False
示例#19
0
    def set_from_file(self, image_info):

        self.set_image_info(image_info)

        x = self.image_info["x"]
        y = self.image_info["y"]
        aspect_ratio = self.image_info["aspect_ratio"]
        file_path = self.image_info["image_path"]

        if os.path.exists(file_path):

            if x == -1 and y == -1:

                self.image.set_from_file(file_path)
                pixbuf = self.image.get_pixbuf()
                self.image_info["x"] = pixbuf.get_width()
                self.image_info["y"] = pixbuf.get_height()
                self.set_visible_child_name("image")
                return True

            else:

                tmp = ImageManager.scale_image(file_path, x, y, aspect_ratio)
                pixbuf = tmp.get_pixbuf()
                self.image_info["x"] = pixbuf.get_width()
                self.image_info["y"] = pixbuf.get_height()
                self.image.set_from_pixbuf(tmp.get_pixbuf())
                self.set_visible_child_name("image")
                return True

        return False
示例#20
0
def update_state(frame, new_done):
    set_done(new_done)
    current_state.append(frame)
    processed_frame = ImageManager.process_frame_for_agent(frame)
    processed_state.append(processed_frame)
    while len(current_state) < 4:
        current_state.append(frame)
        processed_state.append(processed_frame)
示例#21
0
	def __init__(self):
		pygame.init()

		print "Pygame Version: " + pygame.version.ver

		self.mDisplaySurface = None
		self.mTicker = pygame.time.Clock()
		self.mImageManager = ImageManager(self)
		self.mSoundManager = SoundManager(self)
示例#22
0
 def __init__(self):
     self.time = 0.0
     self.color = pygame.color.Color("black")
     self.selectedColor = pygame.color.Color("black")
     Globals.SCREEN.fill(pygame.color.Color("black"))
     self.selectionID = 0
     ImageManager.unloadAll()
     ImageManager.loadSet("Astoria")
     ImageManager.loadSet("debug")
     AudioManager.loadSfxSet("menu")
     AudioManager.loadSfxSet("game")
     if AudioManager.loadedMusic != "title" or\
             not pygame.mixer.music.get_busy():
         AudioManager.loadMusic("title")
         pygame.mixer.music.play(-1)
     Globals.LASTSCREENMAIN = True
     self.astoriaToggleTime = 0.0
     self.astoriaToggleTimeInterval = 2
     self.astoriaOpacity = 0
     temp = ImageManager.levelRes["Astoria"]["Astoria1.png"]
     temp2 = ImageManager.levelRes["Astoria"]["Astoria2.png"]
     width = 500
     height = 200
     ImageManager.levelRes["Astoria"]["Astoria1.png"] =\
         pygame.transform.scale(temp, (width, height))
     ImageManager.levelRes["Astoria"]["Astoria2.png"] =\
         pygame.transform.scale(temp2, (width, height))
示例#23
0
    def deadScreen(self):
        ImageManager.unloadSet("debug")
        AudioManager.unloadSfxSet("debug")
        World.cleanupCompletely()
        Globals.PLAYER = None
        pygame.mixer.music.stop()
        if Globals.MINI_SUNS_INLVL > 0:
            Globals.MINI_SUNS = Globals.MINI_SUNS - 1
        Globals.SCORE = Globals.SCORE - 1000*Globals.MINI_SUNS_INLVL
        if Globals.CURRENT_LEVEL != "five":
            pickCount = random.randint(1, 10)
            index = 0
            if Globals.MINI_SUNS_INLVL > 0:  # remove sun code
                while pickCount > 0:
                    index = (index + 1) % 5
                    if Globals.sunTr()[index]:
                        continue
                    pickCount -= 1
                Globals.SUN_TRACKER[Globals.CURRENT_LEVEL][index] = True
#            Globals.SUN_TRACKER[Globals.CURRENT_LEVEL] = self.sunArray
        Globals.STATE = OverScreen.OverScreen()
        Globals.MINI_SUNS_INLVL = 0
示例#24
0
def makeMonsterSpawner(x, y, mType, level):
    spawner = Entity.Entity()
    spawner.posx = x
    spawner.posy = y
    spawner.rect = pygame.Rect(x, y, 1, 1)
    if level == "one":
        if mType == 0:
            spawner.componentList.append(CSpawnMushroom.CSpawnMushroom(1))
        elif mType == 1:
            spawner.componentList.append(CSpawnBird.CSpawnBird(1))
    elif level == "two":
        if mType == 0:
            spawner.componentList.append(CSpawnVulture.CSpawnVulture(1))
        elif mType == 1:
            spawner.componentList.append(CSpawnRabbit.CSpawnRabbit(1))
    elif level == "three":
        if mType == 0:
            spawner.componentList.append(CSpawnBat.CSpawnBat(1))
        elif mType == 1:
            spawner.componentList.append(CSpawnStalactite.CSpawnStalactite(1))
        elif mType == 2:
            spawner.componentList.append(CSpawnSlime.CSpawnSlime(1))
    elif level == "four":
        if mType == 0:
            spawner.componentList.append(CSpawnOwl.CSpawnOwl(1))
        elif mType == 1:
            spawner.componentList.append(CSpawnIcicle.CSpawnIcicle(1))
        elif mType == 2:
            spawner.componentList.append(CSpawnPenguin.CSpawnPenguin(1))
    elif level == "five":
        if mType == 0:
            ImageManager.loadSet("boss")
            spawner.componentList.append(CSpawnSnowboss.CSpawnSnowboss())
            spawner.initialize()
    if len(spawner.componentList) > 0:
        groups["spawners"].add(spawner)
示例#25
0
 def __init__(self):
     self.time = 0.0
     self.red = pygame.color.Color("red")
     self.yellow = pygame.color.Color("yellow")
     self.blue = pygame.color.Color("blue")
     self.white = pygame.color.Color("white")
     self.color = pygame.color.Color("black")
     self.selectedColor = pygame.color.Color("black")
     Globals.SCREEN.fill(pygame.color.Color("black"))
     self.selectionID = 0
     self.astoriaToggleTime = 0.0
     self.astoriaToggleTimeInterval = 2
     self.astoriaOpacity = 0
     self.skills = [
         Globals.SKILL_JUMP, Globals.SKILL_DAMAGE, Globals.SKILL_MAX_HEALTH]
     self.colorWheel = [self.blue, self.yellow, self.red]
     ImageManager.loadSet("effects")
     self.sunImage = ImageManager.levelRes["effects"]["sun.png"]
     ImageManager.levelRes["effects"]["sun.png"] =\
         pygame.transform.scale(self.sunImage, (50, 50))
     ImageManager.loadSet("player")
     self.playerWalk = ImageManager.levelRes["player"]["Noelwalk.png"]
     ImageManager.levelRes["player"]["Noelwalk.png"] =\
         pygame.transform.scale(self.playerWalk, (50, 75))
     self.playerJump = ImageManager.levelRes["player"]["noel_jump.png"]
     ImageManager.levelRes["player"]["noel_jump.png"] =\
         pygame.transform.scale(self.playerJump, (50, 75))
     self.attack = ImageManager.levelRes["player"]["NoelWithZord.png"]
     ImageManager.levelRes["player"]["NoelWithZord.png"] =\
         pygame.transform.scale(self.attack, (50, 75))
     self.arrow = ImageManager.levelRes["player"]["BowArrow.png"]
     ImageManager.levelRes["player"]["BowArrow.png"] =\
         pygame.transform.scale(self.arrow, (200, 150))
     self.zord = ImageManager.levelRes["player"]["zord.png"]
     ImageManager.levelRes["player"]["zord.png"] =\
         pygame.transform.scale(self.arrow, (50, 50))
示例#26
0
    def create_banner_from_file(self, image_info, output_file=None):

        file_name = image_info.setdefault("image_path")
        x = image_info.setdefault("x")
        y = image_info.setdefault("y")
        custom_frame = image_info.setdefault("custom_frame", False)
        txt = image_info.setdefault("name", None)

        ret = ImageManager.create_banner(file_name, x, y, txt, custom_frame,
                                         output_file)

        if output_file == None:
            image_info["pixbuf"] = ret[1].get_pixbuf()
            self.set_from_pixbuf(image_info)
        else:
            image_info["image_path"] = output_file
            self.set_from_file(image_info)
示例#27
0
def communicateWithPeers(centralServerName, centralServerPort, peerServerPort, \
                         peerServerID, imagedir):
    global centralServer
    global peerServer
    #connect to central server to add host and port to peer list
    centralServer = ContactCentralServer(centralServerName, centralServerPort, \
                                         peerServerPort, peerServerID)
    response = centralServer.connect()
    if (response.find("BAD") != -1):
        print(response[4:])
        print("Exiting")
        sys.exit(0)
    #Create an image manager object that will be passed to
    #both the peer client and the peer server.
    #The peer client will request images from a peer server.
    #The peer server will return requested images to a peer client.
    imageman = ImageManager(imagedir, "")
    peerClient = PeerClient(centralServer, peerServerPort, imageman)
    print("Peer server listening on port " + peerServerPort + ".\n")
    peerClient.start()  # start peer client thread
    peerServer = PeerServer(peerServerPort, imageman)
    peerServer.start()  # start peer server thread
    return peerClient
示例#28
0
def lists_generator(df, items_per_class, samples, train_test):
    """
	df:				dataframe where to load the data from
	samples:		number of images pairs to be trained	
	items_per_class:number of items belonging to the same class inside the dataframe
	train_test:		integer representing whether to generate training (0) or test set (1)

	return:		X_list:	representing a list of samples compared images (1 pair belonging to the 
						same class, N-1 pairs belonging to different classes) as features (1D array)
				y_list:	representing a list of binary values (0 or 1) whether (1) or not (0) 
						the paired images belong to the same class			
	"""

    X_list = []
    y_list = []

    count_same = 0
    count_different = 0

    #	if test set generator, divide the number of samples by 4
    if (train_test == 1):
        samples = int(samples / 4)

    for i in range(0, samples):
        #	randomly choose a class among all of the classes inside the dataframe
        rnd = np.random.choice(range(0, len(df)))
        img_class = int(math.modf(rnd / items_per_class)[1])

        #	randomly choose an image within that class
        rnd1 = np.random.choice(
            range(img_class * items_per_class,
                  (img_class * items_per_class) + items_per_class))

        #	random number to choose whether or not the other image should belong to the same (1) or different class (0)
        rnd_same_different = np.random.choice([0, 1])

        #	randomly choose another image belonging to the same class as only one example
        if (rnd_same_different == 1):
            rnd2 = np.random.choice(
                range(img_class * items_per_class,
                      (img_class * items_per_class) + items_per_class))
            y_list.append(1)
            count_same += 1

        #	randomly choose a class that is different from the one previously computed
        else:
            rnd2 = np.random.choice(
                np.setdiff1d(
                    range(0, len(df)),
                    range(img_class * items_per_class,
                          (img_class * items_per_class) + items_per_class)))
            y_list.append(0)
            count_different += 1

        #	load the images
        img1 = im.load_image(df.iloc[rnd1]["path"])
        img2 = im.load_image(df.iloc[rnd2]["path"])

        #	add in X_list the image generated by overlapping the two images
        X_list.append([im.process_images(img1, img2)])

    if (train_test == 0):
        print("%d same and %d different pairs of images for training set" %
              (count_same, count_different))
    else:
        print("%d same and %d different pairs of images for test set" %
              (count_same, count_different))

    return X_list, y_list
示例#29
0
文件: tumblr.py 项目: eiurur/NNNNN
 def download(self, categorize_result):
     ImageManager.download(categorize_result.filepath,
                           categorize_result.url)
示例#30
0
class ImageViewerWindow(QtGui.QMainWindow):
    def __init__(self):
        super(ImageViewerWindow, self).__init__()

        self.mdiArea = QtGui.QMdiArea()
        self.mdiArea.show()
        self.setCentralWidget(self.mdiArea)

        self.createActions()
        self.createMenus()

        self.fromIdx = 1
        self.toIdx = 0
        self.configWindow = ImageViewerConfigForm(self)
        self.imageDataList = []

        self.setWindowTitle("Image Viewer")
        self.show()

    def open(self):
        fileName = QtGui.QFileDialog.getOpenFileName(self)
        if fileName:
            with open(str(fileName)) as fp:
                jsondict = json.load(fp)

                self.im = ImageManager(jsondict)
                for i in range(self.im.image_num):
                    self.createSubImageViewer(self.im.images[i].id,
                                              self.im.images[i].pixmap,
                                              self.im.images[i].labeled_pixels,
                                              self.im.label_colors)

    def save(self):
        print "Save clicked"
        active_child = self.mdiArea.activeSubWindow()
        if active_child != None:
            active_child.widget().pixmap.save(active_child.widget().name +
                                              ".png")

    def saveAll(self):
        print "Save all clicked"
        for child in self.mdiArea.subWindowList(
                order=QtGui.QMdiArea_CreationOrder):
            child.widget().pixmap.save(child.widget().name + ".png")

    def calcHomograph(self):
        print "Calc Homography"

        self.configWindow.exec_()
        print "From " + str(self.fromIdx) + " to " + str(self.toIdx)
        H = self.im.calcHomographyUsingIndex(self.fromIdx, self.toIdx)
        H_r = self.im.calcHomographyByRegressionUsingIndex(
            self.fromIdx, self.toIdx)

        print H
        print H_r

        print "Error "
        print str(H - H_r)
        '''
        print "Homography"
        for i in range(3):
            for j in range(3):
                print 'H' + str(j) + str(j)
                print '%0.2f' % H[i,j]
                print '%0.2f' % H_r[i,j]
        '''

    def warpImage(self):
        print "Warp image"

        self.configWindow.exec_()
        print "From " + str(self.fromIdx) + " to " + str(self.toIdx)
        self.mapImage(self.fromIdx, self.toIdx)

    def stitch(self, stitch_all=False):
        print "Stitch images"
        Hs = []
        mapped_imgs = []
        transs = []
        self.imageDataList = []

        if stitch_all == True:

            toImg = self.im.images[0].pixmap.toImage()
            self.imageDataList.append((toImg, (0, 0)))
            for i in range(1, self.im.image_num):

                H = self.im.calcHomographyByAutoRANSACUsingIndex(i, 0)
                #H = self.im.calcHomographyUsingIndex(i, 0)
                fromImg = self.im.images[i].pixmap.toImage()

                mapped_from_img, from_trans = self.im.bilinearInterpolation(
                    fromImg, H)
                qpix = QtGui.QPixmap.fromImage(mapped_from_img)
                self.createSubImageViewer(
                    str(i) + " and " + str(0), qpix, [], [])
                Hs.append(H)
                mapped_imgs.append(mapped_from_img)
                transs.append(from_trans)
                self.imageDataList.append((mapped_from_img, from_trans))

                blended_img = self.blendImages(self.imageDataList, False)

                # createSubImageViewer
                qpix = QtGui.QPixmap.fromImage(blended_img)
                windName = str(self.fromIdx) + " and " + str(self.toIdx)
                self.createSubImageViewer(windName, qpix, [], [])

        else:

            if len(self.imageDataList) <= 2:
                self.configWindow.exec_()
                print "From " + str(self.fromIdx) + " to " + str(self.toIdx)

                H = self.im.calcHomographyByAutoRANSACUsingIndex(
                    self.fromIdx, self.toIdx)
                #H = self.im.calcHomographyUsingIndex(self.fromIdx, self.toIdx)
                #H = self.im.calcHomographyUsingRegression(fromIdx, toIdx)
                # call bilinearInterpolation

            fromImg = self.im.images[self.fromIdx].pixmap.toImage()
            toImg = self.im.images[self.toIdx].pixmap.toImage()
            mapped_from_img, from_trans = self.im.bilinearInterpolation(
                fromImg, H)

            self.imageDataList.append((toImg, (0, 0)))
            self.imageDataList.append((mapped_from_img, from_trans))

            blended_img = self.blendImages(self.imageDataList, False)

            # createSubImageViewer
            qpix = QtGui.QPixmap.fromImage(blended_img)
            windName = str(self.fromIdx) + " and "
            windName += str(self.toIdx)
            self.createSubImageViewer(windName, qpix, [], [])

    def auto_ransac(self):
        print "Auto Ransac"

        self.configWindow.exec_()
        print "From " + str(self.fromIdx) + " to " + str(self.toIdx)
        H = self.im.calcHomographyByAutoRANSACUsingIndex(
            self.fromIdx, self.toIdx)

        H_r = self.im.calcHomographyUsingIndex(self.fromIdx, self.toIdx)
        print "H"
        print H
        print "H_r"
        print H_r

        print "Erorr"
        print str(H - H_r)

    def ransac(self):
        print "Ransac"

        self.configWindow.exec_()
        print "From " + str(self.fromIdx) + " to " + str(self.toIdx)
        H = self.im.calcHomographyByRANSACUsingIndex(self.fromIdx, self.toIdx)

        H_r = self.im.calcHomographyUsingIndex(self.fromIdx, self.toIdx)
        print "H"
        print H
        print "H_r"
        print H_r

    def mapImage(self, fromIdx, toIdx):

        # calculate homograph
        H = self.im.calcHomographyUsingIndex(fromIdx, toIdx)
        #H = self.im.calcHomographyUsingRegression(fromIdx, toIdx)
        # call bilinearInterpolation

        fromImg = self.im.images[fromIdx].pixmap.toImage()
        qimg, trans = self.im.bilinearInterpolation(fromImg, H)

        toImg = self.im.images[self.toIdx].pixmap.toImage()
        self.imageDataList.append((toImg, (0, 0)))
        self.imageDataList.append((qimg, trans))

        # createSubImageViewer
        qpix = QtGui.QPixmap.fromImage(qimg)
        self.createSubImageViewer(
            str(fromIdx) + " to " + str(toIdx), qpix, [], [])

    def blendImages(self, imageDataList, enableWeight=False):
        # image ( img, trans )

        xlist = []
        ylist = []
        for imageData in imageDataList:
            img = imageData[0]
            trans = imageData[1]
            xlist.append(trans[0])
            xlist.append(trans[0] + img.width())
            ylist.append(trans[1])
            ylist.append(trans[1] + img.height())

        minX = min(xlist)
        maxX = max(xlist)
        minY = min(ylist)
        maxY = max(ylist)

        blendedImage = QtGui.QImage(maxX - minX, maxY - minY,
                                    QtGui.QImage.Format_ARGB32)

        for x in range(minX, maxX + 1):
            if x % 50 == 0:
                print "processing " + str(x) + "/" + str(maxX)
            for y in range(minY, maxY + 1):
                r_vals, g_vals, b_vals = [], [], []
                dist_vals = []
                dist_sum = 0.0
                for imageData in imageDataList:
                    img = imageData[0]
                    trans = imageData[1]
                    if x >= trans[0] and y >= trans[1] and x < trans[
                            0] + img.width() and y < trans[1] + img.height():
                        val = QtGui.QColor(
                            img.pixel(x - trans[0], y - trans[1]))
                        if val.alpha() > 0:
                            if enableWeight == True:
                                dist = np.sqrt(
                                    float((x -
                                           (trans[0] + img.width()) / 2)**2) +
                                    float((y -
                                           (trans[1] + img.height()) / 2)**2))
                                dist_vals.append((dist))
                                dist_sum += dist
                            r_vals.append(val.red())
                            g_vals.append(val.green())
                            b_vals.append(val.blue())

                if len(r_vals) > 0:
                    if enableWeight == True:
                        dist_vals /= dist_sum
                        avg_r = int(
                            np.mean(np.array(dist_vals) * np.array(r_vals)))
                        avg_g = int(
                            np.mean(np.array(dist_vals) * np.array(g_vals)))
                        avg_b = int(
                            np.mean(np.array(dist_vals) * np.array(b_vals)))
                    else:
                        avg_r = int(np.mean(r_vals))
                        avg_g = int(np.mean(g_vals))
                        avg_b = int(np.mean(b_vals))
                    avg_val = QtGui.QColor(avg_r, avg_g, avg_b)
                    blendedImage.setPixel(QtCore.QPoint(x - minX, y - minY),
                                          avg_val.rgba())

        return blendedImage

    def createActions(self):
        self.openAction = QtGui.QAction("Open", self)
        self.openAction.triggered.connect(self.open)

        self.saveAction = QtGui.QAction("Save", self)
        self.saveAction.triggered.connect(self.save)

        self.homographyAction = QtGui.QAction("Calc Homograph", self)
        self.homographyAction.triggered.connect(self.calcHomograph)

        self.warpImgAction = QtGui.QAction("Warp Image", self)
        self.warpImgAction.triggered.connect(self.warpImage)

        self.stitchAction = QtGui.QAction("Stitch Images", self)
        self.stitchAction.triggered.connect(self.stitch)

        self.ransacAction = QtGui.QAction("Ransac", self)
        self.ransacAction.triggered.connect(self.ransac)

        self.ransacAutoAction = QtGui.QAction("Auto Ransac", self)
        self.ransacAutoAction.triggered.connect(self.auto_ransac)

    def createMenus(self):
        self.fileMenu = self.menuBar().addMenu("&File")
        self.fileMenu.addAction(self.openAction)
        self.fileMenu.addAction(self.saveAction)

        self.fileMenu = self.menuBar().addMenu("&Edit")
        self.fileMenu.addAction(self.homographyAction)
        self.fileMenu.addAction(self.warpImgAction)
        self.fileMenu.addAction(self.stitchAction)
        self.fileMenu.addAction(self.ransacAction)
        self.fileMenu.addAction(self.ransacAutoAction)

    def createSubImageViewer(self, name, pixmap, label_points, label_colors):
        child = ImageView(name, pixmap, label_points, label_colors,
                          self.mdiArea)
        self.mdiArea.addSubWindow(child)
        child.show()
        return child
示例#31
0
def get_exit_score(frame):
    positions = im.get_exit_detection(frame)
    if len(positions):
        return np.ceil(min(positions) / 10)
    return 0
示例#32
0
def get_enemy_hp_bars(frame):
    hp_bar_cnts, debug_frame = im.detect_enemy_hp_bars(frame)
    hp_bars = [im.get_hp_bar_from_cnt(cnt, frame) for cnt in hp_bar_cnts]
    hp_bars = [hp_bar for hp_bar in hp_bars if hp_bar is not None]

    return hp_bars, debug_frame
示例#33
0
        p2 = newpoints2[i]
        #print str(p1) + " -- " + str(p2)
        cv2.circle(cimg1, (p1[0] - point_radius, p1[1] - point_radius),
                   point_radius, rndColors[i], point_radius)
        cv2.circle(cimg2, (p2[0] - point_radius, p2[1] - point_radius),
                   point_radius, rndColors[i], point_radius)
    #cv2.imshow(filename1, cimg1)
    cv2.imwrite(filename1 + "_l.jpg", cimg1)
    #cv2.imshow(filename2, cimg2)
    cv2.imwrite(filename2 + "_l.jpg", cimg2)
    #cv2.waitKey(0)

    print "matched len " + str(len(newpoints1))

    numiters = 2000
    im = ImageManager(None)
    H, best_set = im.ransac2(img1, newpoints1, img2, newpoints2, numiters, 20)
    #H = self.ransac(matchedpoints1, matchedpoints2, numiters)
    print H

    points_num = len(best_set)
    rndColors = []
    for i in range(points_num):
        rndVals = np.random.randint(0, 255, 3)
        rndColors.append((rndVals[0], rndVals[1], rndVals[2]))

    point_radius = 20
    cimg1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2BGR)
    cimg2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2BGR)
    for i in range(points_num):
        #print best_set[i]
示例#34
0
 def _create(self):
     open_canvas(self.WINDOW_WIDTH, self.WINDOW_HEIGHT, self.CAPTION)
     self._m_ImageManager = ImageManager.ImageManager()
     self._m_SoundManager = SoundManager.SoundManager()
     self._build_scene()
     self._m_bRun = True
示例#35
0
 def save(self, media):
     category_reuslt = CategorizeResult(
         url=media['media_url'], filename=media['media_url'].split("/")[-1])
     ImageManager.download(category_reuslt.filepath, category_reuslt.url)
示例#36
0
def is_lvl_transition_screen(frame):
    gray_frame = im.convert_color_to_gray(frame)
    frame_avg = np.average(gray_frame)
    if frame_avg < 30:
        return True
    return False
示例#37
0
import ImageManager as im
import numpy as np
from Utils import Configuration as config
from Utils import GameStateConst
from concurrent import futures
import multiprocessing
import ScreenRecorder
from Utils.Exceptions import FrameRateExceededException, NoFrameCapturedException

play_btn_asset = im.load_asset(config.play_btn_path)
hp_bar_template = im.load_asset(config.hp_bar_path)

lvl_up_text_image_template = im.load_asset(config.lvl_up_text_image_path)
lvl_up_template_hist = im.get_image_hist(lvl_up_text_image_template)

death_message_asset = im.load_asset(config.death_message_path)
death_message_asset_hist = im.get_image_hist(death_message_asset)

gameplay_check_asset = im.load_asset(config.gameplay_check_asset_path)
gameplay_check_asset_hist = im.get_image_hist(gameplay_check_asset)


def start_screen_recorder():
    ScreenRecorder.create()


def stop_screen_recorder():
    ScreenRecorder.stop()


def is_in_menu(frame):
示例#38
0
    def __init__(self):
        ImageManager.loadSet("player")
        ImageManager.loadSet("effects")
        ImageManager.loadSet(Globals.CURRENT_LEVEL)

        if len(World.groups["HUD"].sprites()) == 0:
            healthHud = Entity.Entity()
            healthHud.componentList.append(CHUDHealth.CHUDHealth())
            World.groups["HUD"].add(healthHud)

            #manaHud = Entity.Entity()
            #manaHud.componentList.append(CHUDMana.CHUDMana())
            #World.groups["HUD"].add(manaHud)

            healthText = Entity.Entity()
            healthText.componentList.append(CHUDHealthText.CHUDHealthText())
            World.groups["HUDText"].add(healthText)

            #manaText = Entity.Entity()
            #manaText.componentList.append(CHUDManaText.CHUDManaText())
            #World.groups["HUDText"].add(manaText)

            scoreText = Entity.Entity()
            scoreText.componentList.append(CHUDScoreText.CHUDScoreText())
            World.groups["HUDText"].add(scoreText)

            sunText = Entity.Entity()
            sunText.componentList.append(CHUDSunText.CHUDSunText())
            World.groups["HUDText"].add(sunText)

            if Globals.CURRENT_LEVEL == "five":
                bossHUD = Entity.Entity()
                bossHUD.componentList.append(CHUDBoss.CHUDBoss())
                World.groups["HUD"].add(bossHUD)

        if Globals.PLAYER is None:
            World.loadMap(Globals.CURRENT_LEVEL)
            World.loadBG(Globals.CURRENT_LEVEL)
            World.initialize()

            entity = Entity.Entity()
            entity.componentList.append(CAnimation.CAnimation(
                ImageManager.levelRes["player"]["Noel_SpriteSheet.png"],
                6, 6, 0, 0.17))
            entity.componentList.append(CPhysics.CPhysics())
            entity.componentList.append(CBasicControl.CBasicControl())
            entity.componentList.append(CCollision.CCollision())
            entity.componentList.append(CView.CView())
            entity.componentList.append(
                CLiving.CLiving(Globals.PLAYER_MAX_HEALTH))
            entity.componentList.append(CDamage.CDamage(Globals.PLAYER_DAMAGE))
            entity.componentList.append(CPlayer.CPlayer())
            entity.componentList.append(CDeathParticle.CDeathParticle(
                ImageManager.levelRes["player"]["Noel_Dead.png"],
                3,
                (0, -20),
                0,
                pygame.BLEND_ADD))
            World.groups["player"].add(entity)
            entity.initialize()
            entity.state = 1
            Globals.PLAYER = entity
            Globals.WIN = False
            Globals.TIME = 120

            zord = Entity.Entity()
            zord.componentList.append(CAnimation.CAnimation(
                ImageManager.levelRes["player"]["Zord_Spritesheet.png"],
                6, 6, 0, 0))
            zord.componentList.append(CPhysics.CPhysics())
            zord.accy = 0
            zord.componentList.append(CAttach.CAttach(entity, 53))
            World.groups["equipment"].add(zord)
            zord.initialize()

            if not Globals.CHECKPOINT_SET or Globals.CURRENT_LEVEL == "five":
                Globals.PLAYER.posx = World.playerPos[0]
                Globals.PLAYER.posy = World.playerPos[1]
            else:
                Globals.PLAYER.posx = float(Globals.getCheckpointPos()[0])
                Globals.PLAYER.posy = float(Globals.getCheckpointPos()[1])

        self.timer = 1.0
        self.bossWinTimer = 4.0

        if AudioManager.loadedMusic != Globals.CURRENT_LEVEL or\
                not pygame.mixer.music.get_busy():
            AudioManager.loadMusic(Globals.CURRENT_LEVEL)
            if AudioManager.loadedMusic == Globals.CURRENT_LEVEL:
                pygame.mixer.music.play(-1)
                if Globals.CURRENT_LEVEL == "five":
                    pygame.mixer.music.set_volume(0.1)

        if not Globals.CURRENT_LEVEL == "five":
            self.sunArray = []
            for sun in Globals.SUN_TRACKER[Globals.CURRENT_LEVEL]:
                self.sunArray.append(sun)
示例#39
0
            selection = ''
            # continue to prompt until user quits with '0' or 'q'
            while (selection != '0') and (selection != 'q'):
                print(
                    "\nPlease enter a number of the photo you would like to process (0 or q to quit):"
                )
                for key, value in photoFileDict.items():
                    photoOptions = photoFileDict[key]['fileName']
                    print(key, photoOptions)

                selection = input("What is your choice? ")
                if (selection != '0') and (selection != 'q'):
                    # ensure entered value is valid
                    if ((selection.isdigit() == False)
                            or (int(selection) > numberOfPhotos)):
                        print("INVALID ENTRY!")
                    else:
                        # valid selection, so parse the .jpg file selected
                        parsedImage = im.ImageManager(
                            photoFileDict[int(selection)]['filePath'])
                        parsedImage.parseImage()
                        print("Camera Make:", parsedImage.cameraMake)
                        print("Camera Model:", parsedImage.cameraModel)
                        print("Endian:", parsedImage.endian)
        else:
            print("No Jpg Photos Exist. Aborting")

except Exception as err:
    print("Unknown error in ImageParser::Main: {0}".format(err))
    im.ImageManager.printMoreErrInfo(err)
示例#40
0
def loadMap(cLevel):
    Globals.initSunTracker()

    global key
    global tiles
    global tileSize
    global playerPos
    global tileBuckets
    global world_width

    mapFile = "img/" + cLevel + "/map"
    keyFile = "img/" + cLevel + "/key"

    groups["tiles"].empty()
    groups["tilesObs"].empty()
    groups["spawners"].empty()

    lresources = []
    for resource in ImageManager.levelRes:
        lresources.append(resource)
    for resource in lresources:
        if resource == "one" or resource == "two" or\
                resource == "three" or resource == "four":
            ImageManager.unloadSet(resource)

    ImageManager.loadSet(cLevel)

    key = []
    tiles = {}
    tileSize = 0
    k = open(keyFile)
    y = 0
    x = 0
    for line in k:
        if y == 0:
            iString = ""
            for c in line:
                if c != '\n':
                    iString = iString + c
            tileSize = int(iString)
        else:
            key.append(line)
            temp = 0
            for c in line:
                temp += 1
            if temp > x:
                x = temp
        y += 1
    k.close()

    tileSheet = ImageManager.levelRes[cLevel]["tiles.png"]
    for j in range(y - 1):
        for i in range(x - 1):
            tiles[(i, j)] = tileSheet.subsurface(
                pygame.Rect(i * tileSize, j * tileSize, tileSize, tileSize))

    f = open(mapFile)

    y = 0
    sunID = 0
    for line in f:
        x = 0
        for c in line:
            if c == 'p':
                playerPos = (x * tileSize, y * tileSize)
            elif c == '*':
                Globals.WIN_POS = x * tileSize
            elif c == '-':  # monster 0
                makeMonsterSpawner(x * tileSize, y * tileSize, 0, cLevel)
            elif c == '_':  # monster 1
                makeMonsterSpawner(x * tileSize, y * tileSize, 1, cLevel)
            elif c == '=':  # monster 2
                makeMonsterSpawner(x * tileSize, y * tileSize, 2, cLevel)
            elif c == '+':  # monster 3
                makeMonsterSpawner(x * tileSize, y * tileSize, 3, cLevel)
            elif c == '~':  # sun
                if Globals.SUN_TRACKER[Globals.CURRENT_LEVEL][sunID]:
                    sun = Entity.Entity()
                    sun.componentList.append(CSun.CSun())
                    sun.image = ImageManager.levelRes["effects"]["sun.png"]
                    sun.rect = sun.image.get_rect()
                    sun.rect.x = x * tileSize
                    sun.rect.y = y * tileSize
                    sun.posx = sun.rect.x
                    sun.posy = sun.rect.y
                    groups["enemies"].add(sun)
                    Globals.sunPos()[(sun.rect.x, sun.rect.y)] = sunID
                sunID += 1
            elif c != '\n' and c != ' ':
                block = Entity.Entity()
                block.image = tiles[findKeyPos(c)]
                block.rect = block.image.get_rect()
                block.rect.left = x * tileSize
                block.rect.top = y * tileSize
                if (c >= 'A' and c <= 'Z') or\
                        (c >= '0' and c <= '9'):
                    groups["tilesObs"].add(block)
                else:
                    groups["tiles"].add(block)
            x += 1
        y += 1
    Globals.BOTTOM = y * tileSize
#    block = Entity.Entity()
#    block.image = pygame.Surface((30, 600))
#    block.rect = pygame.Rect((-30, 600, 30, 600))
#    groups["tilesObs"].add(block)

#    entityBuckets = []
    tileBuckets = []
    xmax = (x) * tileSize + cell_size
    ymax = (y) * tileSize + cell_size
    world_width = xmax
    for y in range(ymax / cell_size):
        for x in range(xmax / cell_size):
            tileBuckets.append(Bucket.Bucket(x * cell_size, y * cell_size))
#            entityBuckets.append(Bucket.Bucket(x * cell_size, y * cell_size))

    for tE in groups["tilesObs"]:
        tileBuckets[hashpos(tE.rect.x, tE.rect.y)].add(tE)
        tileBuckets[hashpos(tE.rect.x + tE.rect.width, tE.rect.y)].add(tE)
        tileBuckets[hashpos(tE.rect.x, tE.rect.y + tE.rect.height)].add(tE)
        tileBuckets[hashpos(
            tE.rect.x + tE.rect.width, tE.rect.y + tE.rect.height)].add(tE)
示例#41
0
 def exitScreen(self):
     ImageManager.unloadSet("debug")
     AudioManager.unloadSfxSet("debug")
     pygame.mixer.music.fadeout(1000)
     Globals.STATE = PauseScreen.PauseScreen()
示例#42
0
 def onParseBtnPress(self, event):
     if (self.bitmap.IsShown() == True):
         parsedImage = im.ImageManager(self.fullPath)
         parsedImage.parseImage()
         self.makeTxt.SetLabel("Camera Make: " + parsedImage.cameraMake)
         self.modelTxt.SetLabel("Camera Model: " + parsedImage.cameraModel)
示例#43
0
def is_in_menu(frame):
    play_btn_area = im.get_play_btn_area(frame)

    if im.equal_similarity(play_btn_area, play_btn_asset) > .8:
        return True
    return False