예제 #1
0
    def crop_from_top_left_corner2(self, select_table=0):
        """Crop top left corner based on the current selected table dict and replace self.screnshot with it"""
        self.screenshots1, self.tlcs1, self.count1 = crop_screenshot_with_topleft_corner(
            self.screenshot,
            binary_pil_to_cv2(self.table_dict['topleft_corner']),
            self.scale_defaults)
        self.screenshots2, self.tlcs2, self.count2 = crop_screenshot_with_topleft_corner(
            self.screenshot,
            binary_pil_to_cv2(self.table_dict['topleft_corner2']),
            self.scale_defaults)
        if self.screenshots1 is None:
            if self.screenshots2 is not None:
                self.screenshots = self.screenshots2
                self.tlcs = self.tlcs2
            else:
                return
        else:
            if self.screenshots2 is None:
                self.screenshots = self.screenshots1
                self.tlcs = self.tlcs1
            else:
                self.screenshots = self.screenshots1 + self.screenshots2
                self.tlcs = self.tlcs1 + self.tlcs2

        self.count = self.count1 + self.count2
        if self.count >= 1:
            self.screenshot = self.screenshots[select_table]
            self.tlc = self.tlcs[self.select_table]
            # log.info(f"tlc:{self.tlc}")
            return self.screenshot
        else:
            return
예제 #2
0
def test_card_download():  # ok!
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_4TABLE')
    table_scraper = TableScraper(table_dict)
    # table_scraper.screenshot = Image.open(os.path.join(get_dir('tests', 'screenshots'), 'test5.png'))
    # screnshot = table_scraper.crop_from_top_left_corner()
    CARD_VALUES = "23456789TJQKA"
    CARD_SUITES = "CDHS"
    # CARD_VALUES = "9"
    # CARD_SUITES = "H"
    player = None
    minX = 100000
    minY = 100000
    for value in CARD_VALUES:
        for suit in CARD_SUITES:
            template_cv2 = table_dict[value.lower() + suit.lower() ]

            template_cv2 = binary_pil_to_cv2(template_cv2)
            template_cv2 = template_cv2[:50, :25, :]
            plt.imshow(template_cv2, cmap='gray', interpolation='bicubic')
            plt.show()
            # if player:
            #     search_area = table_dict[image_area][player]
            # else:
            #     search_area = table_dict[image_area]
            log.info(f'{template_cv2.shape}')
            if template_cv2.shape[0] <= minX: minX = template_cv2.shape[0]
            if template_cv2.shape[1] <= minY: minY = template_cv2.shape[1]
            # plt.imshow(template_cv2, cmap='gray', interpolation='bicubic')
            # plt.show()
    log.info(f'minX:{minX},minY:{minY}')
예제 #3
0
def test_is_my_turn():  ## ok!!!
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    test_src = os.environ['test_src']
    table_scraper = TableScraper(table_dict)
    table_scraper.screenshot = Image.open(os.path.join(test_src, '1.PNG'))
    table_scraper.crop_from_top_left_corner2(select_table=0)
    screenshot = table_scraper.crop_from_top_left_corner()

    status = is_template_in_search_area(table_dict, screenshot,
                               'my_turn', 'my_turn_search_area', table_scraper.scale_defaults)
    log.debug(is_template_in_search_area(table_dict, screenshot,
                               'my_turn', 'my_turn_search_area', table_scraper.scale_defaults))
    #
    search_area = table_dict['my_turn_search_area']
    template = table_dict['my_turn']
    template_cv2 = binary_pil_to_cv2(template)
    cropped_screenshot = screenshot.crop((search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2']))
    screenshot_cv2 = pil_to_cv2(cropped_screenshot)

    # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic')   # ok!
    # plt.imshow(template_cv2, cmap='gray', interpolation='bicubic')
    # plt.show()
    assert status == True
예제 #4
0
 def get_gg_poker_rel(self):
     _, gg_poker, count = crop_screenshot_with_topleft_corner(
         self.screenshot, binary_pil_to_cv2(self.table_dict['gg_poker']),
         self.scale_defaults)
     if count >= 1:
         self.gg_poker_rel = gg_poker[0]
         return True
     else:
         return False
예제 #5
0
 def crop_from_top_left_corner(self, select_table=0):
     """Crop top left corner based on the current selected table dict and replace self.screnshot with it"""
     self.screenshots, self.tlcs, self.count = crop_screenshot_with_topleft_corner(
         self.screenshot,
         binary_pil_to_cv2(self.table_dict['topleft_corner']),
         self.scale_defaults)
     if self.count >= 1:
         self.screenshot = self.screenshots[select_table]
         self.tlc = self.tlcs[select_table]
         return self.screenshot
     else:
         return
예제 #6
0
 def crop_from_top_left_corner(self):
     """Crop top left corner based on the current selected table dict and replace self.screnshot with it"""
     self.screenshot, self.tlc = crop_screenshot_with_topleft_corner(self.screenshot,
                                                                     binary_pil_to_cv2(
                                                                         self.table_dict['topleft_corner']))
     return self.screenshot