Beispiel #1
0
    def evaluate_card(self, card_grey_image_array, display=False):
        card = Card(card_index=None, card_file_name=None, card_grey_image_array=card_grey_image_array)
        card.suit_image, card.number_image = get_suit_and_number(card_grey_image_array)

        if display:
            display_image_with_contours(np.array(card_grey_image_array), [card.suit_image.points_array,
                                                                          card.number_image.points_array])
        #Most of the time is here
        return self.evaluate_suit_and_number_images(card)
Beispiel #2
0
def get_suit_and_number(card_grey_image_array, has_2_cards=False, clip_bottom=True, display=False):
    """

    :param image:
    :return: Suit card contour object and number card contour object
    """
    grey_array = card_grey_image_array

    if not has_2_cards and clip_bottom:
        # chips can cover up bottom
        grey_array = grey_array[0:28, :]

    card_contours = list(find_contours(
            grey_array=grey_array,
            min_width=5,
            max_width=15,
        display=display
    ))

    if display:
        display_image_with_contours(grey_array, [c.points_array for c in card_contours])

    if has_2_cards:
        #
        pass

    sorted_by_x = sorted(card_contours, key=lambda c: c.bounding_box.min_x)

    if has_2_cards:

        if len(sorted_by_x) < 4:
            logger.warning("Not enough images for hole cards")
            # display_image_with_contours(grey_array, [c.contour for c in card_contours])
            return None, None, None, None

        sorted_contours_1 = sorted(sorted_by_x[0:2], key=lambda c: c.bounding_box.min_y)
        sorted_contours_2 = sorted(sorted_by_x[-2:], key=lambda c: c.bounding_box.min_y)

        #display_image_with_contours(grey_array, [c.points_array for c in sorted_contours_1])

        # suit, number
        return sorted_contours_1[1], sorted_contours_1[0], sorted_contours_2[1], sorted_contours_2[0]
    else:
        if len(sorted_by_x) < 2:
            logger.warning("Not enough images for cards")
            #display_image_with_contours(grey_array, [c.contour for c in card_contours])
            return None, None

        sorted_by_y = sorted(sorted_by_x[0:2], key=lambda c: c.bounding_box.min_y)
        return sorted_by_y[1], sorted_by_y[0]
Beispiel #3
0
    def evaluate_hole_card_image_array(self, hole_card_image_array):

        card1 = Card(card_index=None, card_file_name=None, card_grey_image_array=hole_card_image_array)
        card2 = Card(card_index=None, card_file_name=None, card_grey_image_array=hole_card_image_array)

        card1.suit_image, card1.number_image, card2.suit_image, card2.number_image = \
            get_suit_and_number(hole_card_image_array, has_2_cards=True, display=False)

        if False:
            # Use to debug hole card detection
            c1 = self.get_test_card('9', 's')
            c2 = self.get_test_card('9', 'd')

            display_image_with_contours(np.array(hole_card_image_array), [
                card1.number_image.points_array, card1.suit_image.points_array,
                c1.number_image.points_array, c2.suit_image.points_array
            ])

        return self.evaluate_suit_and_number_images(card1, scale_polygons=True), self.evaluate_suit_and_number_images(card2, scale_polygons=True)
Beispiel #4
0
    def get_hero_chips_remaining(self, game_area_image_array):
        chips_image_array = cfg.HERO_REMAINING_CHIPS_AREA.clip_2d_array(game_area_image_array)
        #display_image_with_contours(chips_image_array, contours=[])

        chips_image_grey_array = rgb_yx_array_to_grayscale(chips_image_array)

        digit_group_contours = find_contours(grey_array=chips_image_grey_array,
                                       **cfg.CHIPS_REMAINING_DIGIT_GROUPS_CONTOUR_CONFIG,
                                       display=False

                                       )

        digit_group_contours = list(digit_group_contours)

        if False:
            display_image_with_contours(chips_image_grey_array,
                                    [c.points_array for c in digit_group_contours])

        chips_image_grey_array = self.add_spaces_to_digits(
            image_grey_array=chips_image_grey_array,
            digit_group_contours=digit_group_contours
        )

        digit_contours = find_contours(grey_array=chips_image_grey_array,
                                             **cfg.CHIPS_REMAINING_DIGIT_CONTOUR_CONFIG,
                                             display=False

                                             )
        digit_contours = list(digit_contours)
        chips_remaining = self._digit_contours_to_integer(digit_contours)

        logger.info(f"Chips remaining: {chips_remaining}")

        if False:
            display_image_with_contours(chips_image_grey_array,
                                    [c.points_array for c in digit_contours])

        return chips_remaining
Beispiel #5
0
#Your image path i-e receipt path
file_path = os.path.join(cfg.UNIT_TEST_DATA_DIR, 'bet.png')

image = Image.open(file_path)
image_array = np.array(image)

color_val = 200

mask_white = np.all(image_array >= (color_val, color_val, color_val), axis=-1)
0
image_array[np.logical_not(mask_white)] = [0, 0, 0]
#mask_black = np.all(image_array <= (25, 25, 25), axis=-1)
#mask = np.logical_not(np.logical_or(mask_white, mask_black))
#image_array[mask] = [50,50,50]

display_image_with_contours(image_array, [])

#sys.exit(0)

#img = cv2.imread(file_path)

# based on https://stackoverflow.com/questions/40078625/opencv-mser-detect-text-areas-python
img = cv2.cvtColor(image_array, cv2.COLOR_BGR2RGB)

#Convert to gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

vis = img.copy()

#detect regions in gray scale image
regions, _ = mser.detectRegions(gray)