def test_ocr_pp1(): mongo = MongoManager() table_dict = mongo.get_table( "PartyPoker 6 Players Fast Forward $1-$2 NL Hold'em") table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(get_dir('tests', 'screenshots'), '173280759_PreFlop_0.png')) table_scraper.crop_from_top_left_corner() result = ocr(table_scraper.screenshot, 'total_pot_area', table_scraper.table_dict) assert result == 0.09 result = ocr(table_scraper.screenshot, 'call_value', table_scraper.table_dict) assert result == 0.04 result = ocr(table_scraper.screenshot, 'raise_value', table_scraper.table_dict) assert result == 0.1 result = ocr(table_scraper.screenshot, 'player_funds_area', table_scraper.table_dict, player='0') assert result == 1.32
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
def test_table_scraper(): mongo = MongoManager() table_dict = mongo.get_table("PartyPoker 6 Players Fast Forward $1-$2 NL Hold'em") table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(get_dir('tests', 'screenshots'), '173280759_PreFlop_0.png')) table_scraper.crop_from_top_left_corner() table_scraper.is_my_turn() table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button()
def test_table_scraper(): log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_TEST') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(os.environ['test_src'], 'Capture6.PNG')) table_scraper.crop_from_top_left_corner() log.info(f"Is my turn?{table_scraper.is_my_turn()}") table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() # table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button()
def test_all(self): """Test table button""" self.table_name = self.ui.table_name.currentText() from poker.scraper.recognize_table import TableScraper table_dict = mongo.get_table(table_name=self.table_name) table_scraper = TableScraper(table_dict) table_scraper.screenshot = self.original_screenshot table_scraper.crop_from_top_left_corner() table_scraper.is_my_turn() table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button()
def test_table_scraper(): mongo = MongoManager() table_dict = mongo.get_table('default') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(get_dir('tests', 'screenshots'), 'screenshot1.png')) table_scraper.crop_from_top_left_corner() table_scraper.is_my_turn() table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button() table_scraper.get_game_number_on_screen2()
def test_ocr_value(): # ok! for total pot log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_TEST') table_scraper = TableScraper(table_dict) test_src = os.environ['test_src'] table_scraper.screenshot = Image.open(os.path.join(test_src, 'jinyi 0006.PNG')) screenshot = table_scraper.crop_from_top_left_corner() # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic') # ok! # plt.show() # Total pots test # ok!!! search_area = table_dict['total_pot_area'] cropped_screenshot = screenshot.crop((search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) total_pot = get_ocr_float(cropped_screenshot, 'total_pot_area') log.info(f"Total pot {total_pot}") # Current pot test # ok !!! current_round_pot = 0 search_area = table_dict['current_round_pot'] cropped_screenshot = screenshot.crop((search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) current_round_pot = get_ocr_float(cropped_screenshot, 'current_round_pot') log.info(f"Current round pot {current_round_pot}") # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic') # ok! # plt.show() # Player funds test player_funds = [] player_pots = [] for i in range(6): search_area = table_dict['player_funds_area'][str(i)] cropped_screenshot = screenshot.crop( (search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) funds = get_ocr_float(cropped_screenshot, 'player_funds_area') player_funds.append(funds) log.info(f"Player funds: {player_funds}") # Player pots test for i in range(6): search_area = table_dict['player_pot_area'][str(i)] cropped_screenshot = screenshot.crop( (search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) funds = get_ocr_float(cropped_screenshot, 'player_pot_area') player_pots.append(funds) # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic') # plt.show() log.info(f"Player pot: {player_pots}")