def test_blank_image():
    """
    Test OCR with a blank image
    """
    blank_image = np.zeros((300, 300, 3), np.uint8)
    ocr = MinecraftScreenReader(blank_image)

    users = ocr.get_users()
    assert not users
Exemplo n.º 2
0
def test_empty_image():
    """
    Test OCR with a missing image.
    """
    img = cv2.imread("tests/THIS_DOES_NOT_EXIT.png")
    ocr = MinecraftScreenReader(img)

    users = ocr.get_users()
    assert not users
Exemplo n.º 3
0
def test_user_with_teamname():
    """
    Test user extraction logic where user contains prefix of the team name
    """
    ocr = MinecraftScreenReader(None)
    assert ocr._extract_users_from_line("team:user") == ["user"]
    assert ocr._extract_users_from_line("team: user") == ["user"]
    assert ocr._extract_users_from_line("team :user") == ["user"]
    assert ocr._extract_users_from_line("team : user") == ["user"]
Exemplo n.º 4
0
def test_user_with_trailing_v():
    """
    Test user extraction logic where user has a trailing '<space>v' (caused by a tick on the screen)
    """
    assert MinecraftScreenReader._extract_users_from_line("user v") == ["user"]
    assert MinecraftScreenReader._extract_users_from_line("user  v") == [
        "user"
    ]
    assert MinecraftScreenReader._extract_users_from_line("user   v") == [
        "user"
    ]
def test_ocr():
    """
    Test character recognition of a test image.
    """
    img = cv2.imread("tests/test.png")
    ocr = MinecraftScreenReader(img)

    users = ocr.get_users()
    #assert users == ['_byF3l1lx_', 'Sternlicht', 'dramatc', 'StegobertFanyboy', 'UnwichtigsDing', 'lolmcOO1',
    #                 'PrestigePrincess',
    #                 'ClientKnocki', 'iFrostSupreme', 'Marvin__Lp', 'NQRMANY', 'NQRMAN', 'Grammatik']
    print(users)
    assert users == ['_byf3l1lx_', 'sternlicht', 'dramatc',
                     'stegobertfanyboy', 'stegobertfanybo', # OCR adds 2 variations, in case the trailing Y is a tick
                     'unwichtigsding', 'lolmcoo1', 'prestigeprincess', 'clientknocki', 'ifrostsupreme', 'marvin__lp',
                     'nqrmany', 'nqrman',    # OCR adds 2 variations, in case the trailing Y is a tick
                     'grammatik']
Exemplo n.º 6
0
def test_user_with_whitespace():
    """
    Test user extraction logic with trailing whitespace
    """
    ocr = MinecraftScreenReader(None)
    assert ocr._extract_users_from_line("    user    ") == ["user"]
Exemplo n.º 7
0
        "--filter",
        type=str,
        default="blur",
        help="preprocessing method that is applied to the raw image during OCR"
    )
    args = parser.parse_args()
    print(args)

    # load the minecraft screenshot from an existing file (if specified) or take from clipboard
    if args.image:
        raw = cv2.imread(args.image)
    else:
        raw = ImageGrab.grabclipboard()
        raw = cv2.cvtColor(numpy.array(raw), cv2.COLOR_RGB2BGR)

    # extract the users
    image_rdr = MinecraftScreenReader(raw, image_filter=args.filter)
    users = image_rdr.get_users()
    print("Users: ", users)

    # Get the stats. Use the provided url to get stats if provided, otherwise use the default.
    if args.url:
        stats_reader = MinecraftStats(args.url)
    else:
        stats_reader = MinecraftStats()
    stats = stats_reader.get_stats_df(users)
    print(stats)

    # display as a grid (via heatmap)
    stats_reader.plot_table(stats)