コード例 #1
0
    def getMedal(self, medal, pos):
        if medal == 'bronze':
            return Image(Asset.loadpath('homescreen', 'img', 'bronze.png'),
                         pos)
        elif medal == 'silver':
            return Image(Asset.loadpath('homescreen', 'img', 'silver.png'),
                         pos)
        elif medal == 'gold':
            return Image(Asset.loadpath('homescreen', 'img', 'gold.png'), pos)

        return None
コード例 #2
0
 def __init__(self, images, names, metadata):
   self.images = []
   for i in range(len(images)):
     temp_m = metadata['training'][names[i]]
     temp = Image(images[i], name=names[i], metadata=temp_m)
     self.images.append(temp)
   self.filters = []
コード例 #3
0
    def apply_all(self):
        image = self.image

        for i in range(len(self.filter_sequence)):
            filtered = self.apply_filter(i)
            image = Image(filtered)

        return image
コード例 #4
0
 def __init__(self, image=None, name=None, metadata=None):
     self.trueImage = image
     self.image = Image(image, name, metadata)
     self.filter_map = {
         'equalize': cv2.equalizeHist,
         'average': cv2.blur,
         'gaussian': cv2.GaussianBlur,
         'median': cv2.medianBlur,
         'bilateral': cv2.bilateralFilter,
         'laplacian': cv2.Laplacian,
         'prewitt': cv2.filter2D,
         'canny': cv2.Canny,
         'morph': cv2.morphologyEx,
         'threshold': cv2.threshold,
         'adaptive': cv2.adaptiveThreshold,
         'sobel': cv2.Sobel
     }
     self.filter_sequence = []
コード例 #5
0
        def game_intro(screen):
            # Main screen text
            logo = Image(Asset.loadpath('hordelopen', 'img', 'logo.jpg'),
                         [0, 0])
            background = Image(
                Asset.loadpath('hordelopen', 'img', 'background.jpg'), [0, 0])
            intructions = Image(
                Asset.loadpath('hordelopen', 'img', 'intructions.jpg'),
                [215, 185])

            # Buttons
            start_btn = Button()
            quit_btn = Button()

            clock = pygame.time.Clock()
            while True:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        return 'quit'

                screen.gameDisplay.blit(background.image, background.rect)
                screen.gameDisplay.blit(intructions.image, intructions.rect)
                screen.gameDisplay.blit(logo.image, logo.rect)

                check_start = start_btn.setButton("Start", 150, 450, 100, 50,
                                                  Color.GREEN.getRGB(),
                                                  Color.DARK_GREEN.getRGB(),
                                                  screen, 'game')
                check_end = quit_btn.setButton("Return", 550, 450, 100, 50,
                                               Color.RED.getRGB(),
                                               Color.DARK_RED.getRGB(), screen,
                                               'return')

                # Return results of button clicked
                if check_start != None:
                    return 'game'
                elif check_end != None:
                    return 'return'
                else:
                    pygame.display.update()
                    clock.tick(15)
コード例 #6
0
    def apply_in_sequence(self, hist=False):
        image = self.image

        if (hist):
            image.show_image_histogram()
        else:
            image.show_image()

        for i in range(len(self.filter_sequence)):
            filterred = self.apply_filter(i)
            image = Image(filterred)
            if (hist):
                image.show_image_histogram()
            else:
                image.show_image()
        return image
コード例 #7
0
    def startingScreen(self, screen):
        pygame.display.set_caption("Olympische Spelen")
        imgBackground = Image(
            Asset.loadpath('homescreen', 'img', 'background.png'), [0, 0])
        scoreBackground = Image(
            Asset.loadpath('homescreen', 'img', 'scoreboard.png'), [0, 235])

        # Zeilen
        btnZeilen = Image(Asset.loadpath('homescreen', 'img', 'btnZeilen.png'),
                          [241, 350])
        btnZeilenHover = Image(
            Asset.loadpath('homescreen', 'img', 'btnZeilenHover.png'),
            [241, 350])

        # Disk shooting
        btnDiskshooting = Image(
            Asset.loadpath('homescreen', 'img', 'btnDiskShooting.png'),
            [102, 253])
        btnDiskshootingHover = Image(
            Asset.loadpath('homescreen', 'img', 'btnDiskShootingHover.png'),
            [102, 253])

        # Hordelopen
        btnHordelopen = Image(
            Asset.loadpath('homescreen', 'img', 'btnHordelopen.png'),
            [622, 160])
        btnHordelopenHover = Image(
            Asset.loadpath('homescreen', 'img', 'btnHordelopenHover.png'),
            [622, 160])

        # Skiing
        btnSkiing = Image(Asset.loadpath('homescreen', 'img', 'btnBoksen.png'),
                          [320, 202])
        btnSkiingHover = Image(
            Asset.loadpath('homescreen', 'img', 'btnBoksenHover.png'),
            [320, 202])

        btnZwemmen = Image(
            Asset.loadpath('homescreen', 'img', 'btnZwemmen.png'), [39, 75])
        btnZwemmenHover = Image(
            Asset.loadpath('homescreen', 'img', 'btnZwemmenHover.png'),
            [39, 75])

        btnGewichtsheffen = Image(
            Asset.loadpath('homescreen', 'img', 'btnGewichtsheffen.png'),
            [392, 81])
        btnGewichtsheffenHover = Image(
            Asset.loadpath('homescreen', 'img', 'btnGewichtsheffenHover.png'),
            [392, 81])

        while True:
            self.clicked = False
            ev = pygame.event.get()
            for event in ev:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    global clicked
                    self.clicked = True

            screen.gameDisplay.fill((Color.BLACK.getRGB()))
            screen.gameDisplay.blit(imgBackground.image, imgBackground.rect)
            screen.gameDisplay.blit(scoreBackground.image,
                                    scoreBackground.rect)

            # Working games
            btnHordelopenRect = screen.gameDisplay.blit(
                btnHordelopen.image, btnHordelopen.rect)
            btnDiskshootingRect = screen.gameDisplay.blit(
                btnDiskshooting.image, btnDiskshooting.rect)
            btnZeilenRect = screen.gameDisplay.blit(btnZeilen.image,
                                                    btnZeilen.rect)
            btnSkiingRect = screen.gameDisplay.blit(btnSkiing.image,
                                                    btnSkiing.rect)
            btnZwemmenRect = screen.gameDisplay.blit(btnZwemmen.image,
                                                     btnZwemmen.rect)

            # Games that will be tzken out of the game if needed
            btnGewichtsheffenRect = screen.gameDisplay.blit(
                btnGewichtsheffen.image, btnGewichtsheffen.rect)

            self.displayScores(screen)

            # Check if button is clicked
            if btnHordelopenRect.collidepoint(
                    pygame.mouse.get_pos()) and self.clicked:
                return 'hordelopen'
            elif btnDiskshootingRect.collidepoint(
                    pygame.mouse.get_pos()) and self.clicked:
                return 'diskShooting'
            elif btnZeilenRect.collidepoint(
                    pygame.mouse.get_pos()) and self.clicked:
                return 'zeilen'
            elif btnSkiingRect.collidepoint(
                    pygame.mouse.get_pos()) and self.clicked:
                return 'skiing'
            elif btnZwemmenRect.collidepoint(
                    pygame.mouse.get_pos()) and self.clicked:
                return 'zwemmen'
            elif btnGewichtsheffenRect.collidepoint(
                    pygame.mouse.get_pos()) and self.clicked:
                return 'gewichtheffen'

            # On hover effect
            if btnDiskshootingRect.collidepoint(pygame.mouse.get_pos()):
                btnDiskshootingRect = screen.gameDisplay.blit(
                    btnDiskshootingHover.image, btnDiskshootingHover.rect)
            elif btnHordelopenRect.collidepoint(pygame.mouse.get_pos()):
                btnHordelopenRect = screen.gameDisplay.blit(
                    btnHordelopenHover.image, btnHordelopenHover.rect)
            elif btnZeilenRect.collidepoint(pygame.mouse.get_pos()):
                btnZeilenRect = screen.gameDisplay.blit(
                    btnZeilenHover.image, btnZeilenHover.rect)
            elif btnZwemmenRect.collidepoint(pygame.mouse.get_pos()):
                btnZwemmenRect = screen.gameDisplay.blit(
                    btnZwemmenHover.image, btnZwemmenHover.rect)
            elif btnSkiingRect.collidepoint(pygame.mouse.get_pos()):
                btnSkiingRect = screen.gameDisplay.blit(
                    btnSkiingHover.image, btnSkiingHover.rect)
            elif btnGewichtsheffenRect.collidepoint(pygame.mouse.get_pos()):
                btnGewichtsheffenRect = screen.gameDisplay.blit(
                    btnGewichtsheffenHover.image, btnGewichtsheffenHover.rect)

            # If no button has been pressed then stay in start screen
            return 'start'
コード例 #8
0
class FilterSequence():
    def __init__(self, image=None, name=None, metadata=None):
        self.trueImage = image
        self.image = Image(image, name, metadata)
        self.filter_map = {
            'equalize': cv2.equalizeHist,
            'average': cv2.blur,
            'gaussian': cv2.GaussianBlur,
            'median': cv2.medianBlur,
            'bilateral': cv2.bilateralFilter,
            'laplacian': cv2.Laplacian,
            'prewitt': cv2.filter2D,
            'canny': cv2.Canny,
            'morph': cv2.morphologyEx,
            'threshold': cv2.threshold,
            'adaptive': cv2.adaptiveThreshold,
            'sobel': cv2.Sobel
        }
        self.filter_sequence = []

    def apply_filter(self, i):
        filt, config = self.filter_sequence[i]
        func = self.filter_map[filt]
        imn = 'src' if filt != 'canny' else 'image'
        config[imn] = self.image.image
        try:
            filtered = func(**config)
        except TypeError as e:
            print(filt)
            raise Exception(e)

        if (filt == 'threshold'):
            filtered = filtered[1]

        if (filt == 'equalize'):
            self.trueImage = filtered

        return filtered

    def apply_and_draw(self, rectangle=(17, 13)):
        image = self.apply_all()
        img = image.image
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT, rectangle)
        dilated = cv2.dilate(img, kernel, 1)

        _, contours1, _ = cv2.findContours(dilated, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)

        imgc1 = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
        cv2.drawContours(imgc1, contours1, -1, (0, 255, 0), 2)
        image.show_image(imgc1)

    def apply_and_draw2(self,
                        rectangle=(17, 13),
                        show=True,
                        ratio=(0.3, 20),
                        area=(2000, 23000)):
        image = self.apply_all()
        img = image.image

        kernel = cv2.getStructuringElement(cv2.MORPH_RECT, rectangle)
        dilated = cv2.dilate(img, kernel, 1)
        _, contours1, _ = cv2.findContours(dilated, cv2.RETR_EXTERNAL,
                                           cv2.CHAIN_APPROX_SIMPLE)

        color = cv2.cvtColor(self.trueImage, cv2.COLOR_GRAY2BGR)

        for cnt in contours1:
            epsilon = 0.05 * cv2.arcLength(cnt, True)
            approx = cv2.approxPolyDP(cnt, epsilon, True)

            if (len(approx) == 4):
                x, y, w, h = cv2.boundingRect(cnt)
                cv2.rectangle(color, (x, y), (x + w, y + h), (255, 0, 0), 2)
                ar = 1.0 * h / 2

                if (ar >= ratio[0] and ar <= ratio[1] and h * w >= area[0]
                        and h * w <= area[1]):
                    self.image.add_sel_contour((x, y, w, h))
                    cv2.rectangle(color, (x, y), (x + w, y + h), (0, 255, 0),
                                  2)
                else:
                    self.image.add_contour((x, y, w, h))
        if (show):
            image.show_image(color)

    def add_filter(self, name, config):
        self.filter_sequence.append((name, config))

    def plot_all_filters(self, hist=False):
        image = self.image

        if (hist):
            image.show_image_histogram()
        else:
            image.show_image()

        for i in range(len(self.filter_sequence)):
            filtered = self.apply_filter(i)
            if (hist):
                image.show_image_histogram(filtered)
            else:
                image.show_image(filtered)

    def apply_all(self):
        image = self.image

        for i in range(len(self.filter_sequence)):
            filtered = self.apply_filter(i)
            image = Image(filtered)

        return image

    def apply_in_sequence(self, hist=False):
        image = self.image

        if (hist):
            image.show_image_histogram()
        else:
            image.show_image()

        for i in range(len(self.filter_sequence)):
            filterred = self.apply_filter(i)
            image = Image(filterred)
            if (hist):
                image.show_image_histogram()
            else:
                image.show_image()
        return image
コード例 #9
0
def endscreen(screen, game, score):
    textScore = ''

    def text_objects(text, font):
        textSurface = font.render(text, True, Color.WHITE.getRGB())
        return textSurface, textSurface.get_rect()

    def button(msg, x, y, w, h, ic, ac, action=None):
        # Button click action
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        # mouse[0] = x coordinates of mouse,
        # mouse[1] = y coordinates of mouse,
        # x = position button | horizontal
        # y = position button | vertical
        # w = width button
        # h = height button
        # ic = background-color
        # ac = background-color on hover
        if x + w > mouse[0] > x and y + h > mouse[1] > y:
            # You are hovering over the button
            pygame.draw.rect(screen.gameDisplay, ac, (x, y, w, h))
            if click[0] == 1 and action != None:
                return action
        else:
            pygame.draw.rect(screen.gameDisplay, ic, (x, y, w, h))

        # Button text
        smallText = pygame.font.Font(Asset.loadpath('font', 'roboto', 'Roboto-Medium.ttf'), 20)
        textSurf, textRect = text_objects(msg, smallText)
        textRect.center = ((x + (w / 2)), (y + (h / 2)))
        screen.gameDisplay.blit(textSurf, textRect)

    def get_medal(game):
        textScore = ''
        if game == 'diskShooting':
            if score >= 8 and score <= 10:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score > 10 and score < 15:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score == 15:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'hordelopen':
            if score >= 1000 and score <= 1200:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score > 1200 and score < 1400:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score >= 1400:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'zeilen':
            if score == 3 or score == 2:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score == 1:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score == 0:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'skiing':
            if score >= 4 and score <= 7:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score > 7 and score < 14:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score >= 14:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'zwemmen':
            if score < 2000 and score >= 1500:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score < 1500 and score >= 1200:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score < 1200:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'gewichtheffen':
            if score == 1:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score == 2:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score == 3:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"

        return [medal, textScore]

    medal_array = get_medal(game)

    if isinstance(medal_array, str):
        medal = medal_array
    else:
        medal = medal_array[0]
        textScore = medal_array[1]

    if game == 'diskShooting':
        background = Image(Asset.loadpath('disk_shooting', 'img', 'background_intro.jpg'), [0, 0])
    if game == 'hordelopen':
        background = Image(Asset.loadpath('hordelopen', 'img', 'background.jpg'), [0, 0])
    if game == 'zeilen':
        background = Image(Asset.loadpath('zeilen', 'img', 'background.jpg'), [0, 0])
    if game == 'skiing':
        background = Image(Asset.loadpath('skiing', 'img', 'background.jpg'), [0, 0])
    if game == 'zwemmen':
        background = Image(Asset.loadpath('zwemmen', 'img', 'background.jpg'), [0, 0])
    if game == 'gewichtheffen':
        background = Image(Asset.loadpath('gewichtheffen', 'img', 'homescherm.jpg'), [0, 0])

    clock = pygame.time.Clock()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return None
        screen.gameDisplay.blit(background.image, background.rect)

        largeText = pygame.font.Font(Asset.loadpath('font', 'roboto', 'Roboto-Medium.ttf'), 50)
        TextSurf, TextRect = text_objects("Your score: " + str(score), largeText)
        TextRect.center = ((800 / 2), (600 / 4))
        screen.gameDisplay.blit(TextSurf, TextRect)

        largeText = pygame.font.Font(Asset.loadpath('font', 'roboto', 'Roboto-Medium.ttf'), 50)
        if isinstance(medal, str):
            TextSurf, TextRect = text_objects("Your Medal: " + medal, largeText)
        else:
            TextSurf, TextRect = text_objects("Your Medal: ", largeText)
            screen.gameDisplay.blit(medal.image, medal.rect)

        TextRect.center = ((800 / 2), (600 / 3))
        screen.gameDisplay.blit(TextSurf, TextRect)

        retry_btn = button("Retry", 150, 450, 100, 50, Color.GREEN.getRGB(), Color.DARK_GREEN.getRGB(), game)
        quit_btn = button("Go back", 550, 450, 100, 50, Color.RED.getRGB(), Color.DARK_RED.getRGB(), 'start')

        # Return results of button clicked
        if retry_btn != None:
            return [retry_btn, game, textScore]
        elif quit_btn != None:
            return [quit_btn, game, textScore]
        else:
            pygame.display.update()
            clock.tick(15)
コード例 #10
0
    def get_medal(game):
        textScore = ''
        if game == 'diskShooting':
            if score >= 8 and score <= 10:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score > 10 and score < 15:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score == 15:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'hordelopen':
            if score >= 1000 and score <= 1200:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score > 1200 and score < 1400:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score >= 1400:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'zeilen':
            if score == 3 or score == 2:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score == 1:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score == 0:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'skiing':
            if score >= 4 and score <= 7:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score > 7 and score < 14:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score >= 14:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'zwemmen':
            if score < 2000 and score >= 1500:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score < 1500 and score >= 1200:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score < 1200:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"
        if game == 'gewichtheffen':
            if score == 1:
                medal = Image(Asset.loadpath('homescreen', 'img', 'bronze.png'), [350, 250])
                textScore = 'bronze'
            elif score == 2:
                medal = Image(Asset.loadpath('homescreen', 'img', 'silver.png'), [350, 250])
                textScore = 'silver'
            elif score == 3:
                medal = Image(Asset.loadpath('homescreen', 'img', 'gold.png'), [350, 250])
                textScore = 'gold'
            else:
                return "better luck next time"

        return [medal, textScore]