Ejemplo n.º 1
0
def test_that_ocr_still_returns_if_region_doesnt_intersect_with_frame(region):
    frame = load_image("ocr/menu.png")
    result = stbt.ocr(frame=frame, region=region)
    assert result == u''
Ejemplo n.º 2
0
def test_char_whitelist():
    # Without char_whitelist tesseract reads "OO" (the letter oh).
    assert u'00' == stbt.ocr(frame=load_image('ocr/00.png'),
                             mode=stbt.OcrMode.SINGLE_WORD,
                             char_whitelist="0123456789")
Ejemplo n.º 3
0
def test_user_dictionary_with_non_english_language(words):
    assert u'192.168.10.1' == stbt.ocr(
        frame=load_image('ocr/192.168.10.1.png'),
        mode=stbt.OcrMode.SINGLE_WORD,
        lang="deu",
        tesseract_user_words=words)
Ejemplo n.º 4
0
 def ocr():
     return stbt.ocr(frame=frame)
Ejemplo n.º 5
0
def test_that_default_language_is_configurable():
    f = load_image("ocr/unicode.png")
    assert not stbt.match_text(u"Röthlisberger", f)  # reads Réthlisberger
    with temporary_config({"ocr.lang": "deu"}):
        assert stbt.match_text(u"Röthlisberger", f)
        assert u"Röthlisberger" in stbt.ocr(f)
Ejemplo n.º 6
0
def test_that_ocr_reads_unicode():
    text = stbt.ocr(frame=load_image('ocr/unicode.png'), lang='eng+deu')
    assert isinstance(text, str)
    assert u'£500\nDavid Röthlisberger' == text
Ejemplo n.º 7
0
def test_that_ocr_can_read_small_text():
    text = stbt.ocr(frame=load_image('ocr/small.png'))
    assert u'Small anti-aliased text is hard to read\nunless you magnify' == \
        text
Ejemplo n.º 8
0
def test_that_ocr_region_none_isnt_allowed(region):
    f = load_image("ocr/small.png")
    with pytest.raises((TypeError, ValueError)):
        stbt.ocr(frame=f, region=region)
    with pytest.raises((TypeError, ValueError)):
        stbt.match_text("Small", frame=f, region=region)
Ejemplo n.º 9
0
 def cached_ocr2():
     return stbt.ocr(frame=frame2, region=r)
Ejemplo n.º 10
0
 def cached_ocr1():
     return stbt.ocr(frame=frame, region=r)
Ejemplo n.º 11
0
def test_ocr_on_static_images(image, expected_text, region, mode):
    kwargs = {"region": region}
    if mode is not None:
        kwargs["mode"] = mode
    text = stbt.ocr(load_image("ocr/" + image), **kwargs)
    assert text == expected_text
Ejemplo n.º 12
0
def test_ocr_on_text_next_to_image_match():
    frame = load_image("action-panel.png")
    m = stbt.match("action-panel-blue-button.png", frame)
    assert "YOUVIEW MENU" == stbt.ocr(frame,
                                      region=m.region.right_of(width=150))