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''
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")
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)
def ocr(): return stbt.ocr(frame=frame)
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)
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
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
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)
def cached_ocr2(): return stbt.ocr(frame=frame2, region=r)
def cached_ocr1(): return stbt.ocr(frame=frame, region=r)
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
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))