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_4ocr_valu44(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) file_name = get_dir(os.path.join('log', 'pics', 'table_b_16.png')) table_scraper.screenshot = Image.open(file_name) # table_scraper.crop_from_top_left_corner2(select_table=0) if is_debug: # table_scraper.screenshot.save('log/pics/table1.png') file_name = get_dir(os.path.join('log', 'pics', 'table_label.png')) save_table_rectangle_cv2(table_scraper.screenshot, table_dict, file_name) table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_player_pots() log.info(f"{table_scraper.total_pot}") log.info(f"{table_scraper.current_round_pot}") log.info(f"{table_scraper.player_funds}") log.info(f"{table_scraper.player_pots}") # pytest.assume(table_scraper.total_pot == 4.0) # assert table_scraper.total_pot == 4.0 # pytest.assume(table_scraper.player_pots == [-1.0, -1.0, -1.0, 0.5, -1.0, 1.0]) pytest.assume(table_scraper.current_round_pot == 2.0)
def test_preflop_nodelist2(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open(os.path.join(os.environ['test_src'], '14.png')) t.crop_from_top_left_corner2(select_table=3) if is_debug: t.screenshot.save('log/pics/active_player2.png') preflop_state_Zenith = CurrentHandPreflopStateZenith() h = History() preflop_state_Zenith.get_players_status(t)
def test_miss_player4(): # Not pass mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open( r"C:\Users\jinyi\source\repos\Project1\x64\Debug\screenshots\miss_player\sitting_out3.png" ) # t.crop_from_top_left_corner2(select_table=0) if is_debug: t.screenshot.save('log/pics/miss_player2.png') t.get_miss_player() assert t.miss_player == [5]
def test_active_player(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open(os.path.join(os.environ['test_src'], '27.png')) t.crop_from_top_left_corner2(select_table=1) if is_debug: t.screenshot.save('log/pics/active_player.png') preflop_state_Zenith = CurrentHandPreflopStateZenith() h = History() preflop_state_Zenith.get_players_status(t) pytest.assume(preflop_state_Zenith.action == 'LJ_1.0') pytest.assume(preflop_state_Zenith.now_player_order == 1)
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}")
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}')
def test_players_in_game5(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open(os.path.join(os.environ['test_src'], '5.png')) t.crop_from_top_left_corner2(select_table=0) if is_debug: t.screenshot.save('log/pics/players_in_game.png') t.get_players_in_game() t.get_dealer_position2() assert t.players_in_game == [0, 2, 5] assert t.dealer_position == 3
def test_label_pos0(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) prefix = 'b_16' table_scraper.screenshot = Image.open(get_dir(os.path.join('log', 'pics', 'table_' + prefix + '.png'))) for i in [0]: for j in [0]: # table_scraper.crop_from_top_left_corner2(select_table=0) if is_debug: file_name = get_dir(os.path.join('log', 'pics', 'table_label_pos_' + str(i) + '_' + str(j) + '.png')) """ Move table by delta_x = -8 , delta_y = -5 from config.ini """ save_table_rectangle_cv2(table_scraper.screenshot, table_dict, file_name) return True
def test_6table_and_my_cards6(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(os.environ['test_src1'], '5.png')) table_scraper.crop_from_top_left_corner2(select_table=0) table_scraper.get_my_cards3() assert set(table_scraper.my_cards) == set(['7D', '7H']) # ok
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_and_my_cards39(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(os.environ['test_src'], '10.png')) table_scraper.crop_from_top_left_corner2(select_table=3) table_scraper.get_my_cards3() print(table_scraper.table_cards) assert set(table_scraper.my_cards) == {'AH', 'KC'} # Passed
def test_table_and_my_cards11(): # 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(os.environ['test_src'], '2.png')) table_scraper.crop_from_top_left_corner2(select_table=1) table_scraper.get_table_cards2() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'QS', '8C', '5H', '8D'} # Miss 5H, 8C => Passed by resize
def test_table_and_my_cards50(): # 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(os.environ['test_src'], '15.png')) table_scraper.crop_from_top_left_corner2(select_table=2) table_scraper.get_table_cards2() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'AS', '2S', '6S', '8C', '7H'} # Miss AS, 6S
def test_table_and_my_cards27(): # 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(os.environ['test_test'], '4.png')) table_scraper.crop_from_top_left_corner2(select_table=4) table_scraper.get_table_cards2() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'4C', '6C', '2H'} # Miss 4C => Passed by resize => Miss 4C, 6C
def test_table_and_my_cards15(): # 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(os.environ['test_test'], '1.png')) table_scraper.crop_from_top_left_corner2(select_table=3) table_scraper.get_table_cards2() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'5C', 'QS', 'JH', '8D'} # ok
def test_table_and_my_cards30(): # 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(os.environ['test_test'], '5.png')) table_scraper.crop_from_top_left_corner2(select_table=4) table_scraper.get_table_cards2() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'3C', '5C', '7S', '2D'} # Miss 3C, 5C => FIXED BY UPDATE SIZE
def test_card_upload(): # OK! mongo = MongoManager() table_dict = mongo.get_table('GG_TEST') 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" for value in CARD_VALUES: for suit in CARD_SUITES: fileName = value.upper() + suit.lower() + '.png' label = value.lower() + suit.lower() pil_image = Image.open(os.path.join('../../../card-detector\\images', fileName)) mongo.update_table_image(pil_image, label=label, table_name='GG_TEST')
def test_6table_and_my_cards5(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) # log.info(f'codebase dir: {get_dir("codebase")}') # log.info(f'cards dir: {get_dir(os.path.join("cards","values"))}') table_scraper.screenshot = Image.open(os.path.join(os.environ['test_src1'], '4.png')) table_scraper.crop_from_top_left_corner2(select_table=0) table_scraper.get_my_cards3() log.info(f'My cards: {table_scraper.my_cards}') assert set(table_scraper.my_cards) == set(['9H', 'KD']) # 8H duplicates 9H
def test_table_and_my_cards16(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_test'], '2.png')) table_scraper.crop_from_top_left_corner2(select_table=1) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'7S', '6H', '4D', '6S', '8S'} # Additional 8H
def test_table_and_my_cards24(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_test'], '4.png')) table_scraper.crop_from_top_left_corner2(select_table=1) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'KS', '3D', '4S', 'AS' } # Miss AS => Passed by resize
def test_players_in_game11(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open( get_dir(os.path.join('log', 'pics', 'table_c_2.png'))) # t.crop_from_top_left_corner2(select_table=0) if is_debug: t.screenshot.save('log/pics/players_in_game.png') t.get_players_in_game() t.get_dealer_position2() assert t.players_in_game == [0, 1, 2, 3, 4, 5] assert t.dealer_position == 3
def test_table_and_my_cards64(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_4table'], '2.png')) table_scraper.crop_from_top_left_corner2(select_table=0) # config = get_config() # table_size = config['DEFAULT']['table_size'] # log.info(f'table_size:{table_size}') # scale_m = scale_cal(table_size, 'table_cards_area') # log.info(f'scale_m:{scale_m}') table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'4C', '6S', '4H', '7C', 'QD'}
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("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_and_my_cards4(): # 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(os.environ['test_src1'], '3.png')) table_scraper.crop_from_top_left_corner2(select_table=0) 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_player_pots() 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() assert set(table_scraper.my_cards) == set(['AD', '9S']) # ok assert table_scraper.player_funds == [22.5, 134.5, 205.0, 71.0, 100.0, 100.0] assert table_scraper.player_pots == [0.5, 1.0, 1.0, 2.0, '', '']
def test_table_and_my_cards8(): # 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(os.environ['test_src1'], '20.png')) table_scraper.crop_from_top_left_corner2(select_table=0) 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_player_pots() 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() assert set(table_scraper.my_cards) == set(['4S', '4C']) # ok # assert table_scraper.player_funds == [13.0, 13.5, 148.5, 77.5, 98.0, 104.0] #Actual :[13.0, 13.5, 148.5, 77.5, 8.0, 104.0] assert table_scraper.player_pots == [1.0, 2.5, '', '', 2.5, 0.5] # Actual :['', '', 5.5, 0.0, '', '']
def test_table_and_my_cards5(): # 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(os.environ['test_src1'], '4.png')) table_scraper.crop_from_top_left_corner2(select_table=0) 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_player_pots() 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() print(f'My cards: {table_scraper.my_cards}') assert set(table_scraper.my_cards) == set(['9H', 'KD']) # 8H duplicates 9H assert table_scraper.player_funds == [22.5, 141.5, 203.0, 71.0, 100.0, 100.0] assert table_scraper.player_pots == ['', 0.5, 1.0, '', '', ''] # Actual :['', 0.5, 1.0, 0.0, '', '']
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_table_and_my_cards1(): # 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(os.environ['test_src'], '1.png')) table_scraper.crop_from_top_left_corner2() 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_player_pots() 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() assert set(table_scraper.my_cards) == set(['7H', 'AD']) # ok # assert table_scraper.table_cards == ['3H', '6H', 'JS'] assert table_scraper.player_funds == [23.0, 100.0, 42.0, 23.0, 97.5, 102.0] assert table_scraper.player_pots == ['', '', 6.0, '', '', '']