Exemplo n.º 1
0
    def find(self, pixel_similarity):
        path = "saves/" + self.__name + "/temp/"
        character_images = (file for file in os.listdir(path)
                            if os.path.isfile(os.path.join(path, file)))

        self.__sorted_images = []
        white_test = White(float(loadconfig("testwhite")))
        image = pygame.image.load(path + character_images.next())
        width, height = image.get_rect().size

        for column in range(20):
            for row in range(5):
                image = Image.open("files/black.jpeg")
                photo = ImageTk.PhotoImage(image)
                self.__character[column][row].config(image=photo)
                self.__character[column][row].image = photo

        for image_name in character_images:
            full_path = path + image_name
            white_counter = [0, 0, 0, 0]
            found = False
            image = pygame.image.load(full_path)
            for x in range(width):
                for y in range(height):
                    if white_test.test(image.get_at((x, y))):
                        if y < int(height / 4):
                            white_counter[0] += 1
                        elif y < int(height / 4 * 2):
                            white_counter[1] += 1
                        elif y < int(height / 4 * 3):
                            white_counter[2] += 1
                        else:
                            white_counter[3] += 1

            for case in range(len(self.__sorted_images)):
                #print sorted_images[case][0],
                if self.__sorted_images[case][0][0] <= white_counter[0] + pixel_similarity and \
                   self.__sorted_images[case][0][0] >= white_counter[0] - pixel_similarity and \
                   self.__sorted_images[case][0][1] <= white_counter[1] + pixel_similarity and \
                   self.__sorted_images[case][0][1] >= white_counter[1] - pixel_similarity and \
                   self.__sorted_images[case][0][2] <= white_counter[2] + pixel_similarity and \
                   self.__sorted_images[case][0][2] >= white_counter[2] - pixel_similarity and \
                   self.__sorted_images[case][0][3] <= white_counter[3] + pixel_similarity and \
                   self.__sorted_images[case][0][3] >= white_counter[3] - pixel_similarity:
                    self.__sorted_images[case][1].append(full_path)
                    found = True
            if not found:
                self.__sorted_images.append([white_counter, [full_path]])

        for image_column in range(len(self.__sorted_images)):
            for image_row in range(len(self.__sorted_images[image_column][1])):
                if image_row < 5 and image_column < 20:
                    image = Image.open(self.__sorted_images[image_column][1][image_row])
                    photo = ImageTk.PhotoImage(image)
                    self.__character[image_column][image_row].config(image=photo)
                    self.__character[image_column][image_row].image = photo
Exemplo n.º 2
0
Arquivo: vbat.py Projeto: rec/vbat
 def __init__(self, name):
     self.__field = []
     video = loadconfig("video")
     camx = int(loadconfig("camx"))
     camy = int(loadconfig("camy"))
     self.__percent = int(loadconfig("percent")) * 2
     self.__grayvalue = float(loadconfig("testwhite"))
     self.__divider = int(loadconfig("divider"))
     coofile = "saves/" + name + "/" + name + ".coo"
     self.createfield(coofile)
     self.TemplateFolder = "saves/" + name + "/" + name + ".templates"
     self.__matrix, self.__antimatrix, self.__characterdata = self.__creatematrix()
     self.__grabber = CamLib(video, int(camx), int(camy))
     self.__white = White(self.__grayvalue)