本文整理汇总了Python中stbt.ocr函数的典型用法代码示例。如果您正苦于以下问题:Python ocr函数的具体用法?Python ocr怎么用?Python ocr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ocr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_that_match_text_gives_tesseract_a_hint
def test_that_match_text_gives_tesseract_a_hint():
frame = cv2.imread("tests/ocr/itv-player.png")
if "ITV Player" in stbt.ocr(frame=frame):
raise SkipTest("Tesseract doesn't need a hint")
if "ITV Player" not in stbt.ocr(frame=frame, tesseract_user_words=["ITV"]):
raise SkipTest("Giving tesseract a hint doesn't help")
assert stbt.match_text("ITV Player", frame=frame)
示例2: test_that_with_old_tesseract_ocr_raises_an_exception_with_patterns
def test_that_with_old_tesseract_ocr_raises_an_exception_with_patterns():
# pylint: disable=W0212
if stbt._tesseract_version() >= distutils.version.LooseVersion('3.03'):
raise SkipTest('tesseract is too new')
stbt.ocr(
frame=cv2.imread('tests/ocr/UJJM2LGE.png'),
mode=stbt.OcrMode.SINGLE_WORD,
tesseract_user_patterns=[r'\n\n\n\n\n\n\n\n'])
示例3: test_ocr_text_color
def test_ocr_text_color(image, color, expected, region):
frame = load_image(image)
mode = stbt.OcrMode.SINGLE_LINE
assert expected not in stbt.ocr(frame, region, mode)
assert expected == stbt.ocr(frame, region, mode, text_color=color)
assert not stbt.match_text(expected, frame, region, mode)
assert stbt.match_text(expected, frame, region, mode, text_color=color)
示例4: test_that_setting_config_options_has_an_effect
def test_that_setting_config_options_has_an_effect():
# Unfortunately there are many tesseract config options and they are very
# complicated so it's difficult to write a test that tests that a config
# option is having the correct effect. Due to the difficulty in determining
# "correctness" instead here we test that setting a config option has an
# effect at all. This at least excercises our code which sets config
# options. I'm not happy about this and I hope to be able to replace this
# once we have more experience with these settings in the real world.
assert (stbt.ocr(frame=cv2.imread('tests/ocr/ambig.png'),
tesseract_config={"tessedit_create_hocr": 1}) !=
stbt.ocr(frame=cv2.imread('tests/ocr/ambig.png')))
示例5: test_ocr_text_color_threshold
def test_ocr_text_color_threshold():
f = load_image("ocr/blue-search-white-guide.png")
c = (220, 220, 220)
assert stbt.ocr(f) != "Guide"
# pylint:disable=fixme
# TODO: Find an example where text_color_threshold is necessary. Since
# tesseract 4.0.0 the default text_color_threshold actually works.
# assert stbt.ocr(f, text_color=c) != "Guide"
assert stbt.ocr(f, text_color=c, text_color_threshold=50) == "Guide"
with temporary_config({'ocr.text_color_threshold': '50'}):
assert stbt.ocr(f, text_color=c) == "Guide"
示例6: test_that_ocr_engine_has_an_effect
def test_that_ocr_engine_has_an_effect():
if _tesseract_version() < LooseVersion("4.0"):
raise SkipTest('tesseract is too old')
f = load_image("ocr/ambig.png")
# This is a regression in tesseract 4.0's legacy engine, compared to 3.04:
assert "sillyness" not in stbt.ocr(f, engine=stbt.OcrEngine.TESSERACT)
assert "sillyness" not in stbt.ocr(f)
# ...but the new LSTM engine does read it correctly:
assert "sillyness" in stbt.ocr(f, engine=stbt.OcrEngine.LSTM)
with temporary_config({'ocr.engine': 'LSTM'}):
assert "sillyness" in stbt.ocr(f)
示例7: test_that_ligatures_and_ambiguous_punctuation_are_normalised
def test_that_ligatures_and_ambiguous_punctuation_are_normalised():
frame = cv2.imread('tests/ocr/ambig.png')
text = stbt.ocr(frame)
text = text.replace("horizonta|", "horizontal") # for tesseract < 3.03
assert ligature_text == text
assert stbt.match_text("em-dash,", frame)
assert stbt.match_text(u"em\u2014dash,", frame)
示例8: title
def title(self):
"""
The base class provides a ``self._frame`` member. Here we're using
`stbt.ocr` to extract the dialog's title text from this frame. This is
the basic form that many Frame Object properties will take.
This property demonstrates an advantage of Frame Objects. Your
testcases now look like this::
assert Dialog().title == "Information"
instead of this::
assert stbt.ocr(region=stbt.Region(396, 249, 500, 50)) == "Information"
This is clearer because it reveals the intention of the testcase author
(we're looking for the word in the *title* of the dialog). It is also
easier (cheaper) to maintain: If the position of the title moves, you
only need to update the implementation of ``Dialog.title``; you won't
need to change any of your testcases.
When defining Frame Objects you must take care to pass ``self._frame``
into every call to an image processing function (like our ``title``
property does when it calls ``ocr``, above). Otherwise the return
values won't correspond to the frame you were expecting.
"""
return stbt.ocr(region=stbt.Region(396, 249, 500, 50),
frame=self._frame)
示例9: test_that_passing_patterns_helps_reading_serial_codes
def test_that_passing_patterns_helps_reading_serial_codes():
# Test that this test is valid (e.g. tesseract will read it wrong without
# help):
assert u'UJJM2LGE' != stbt.ocr(
frame=cv2.imread('tests/ocr/UJJM2LGE.png'),
mode=stbt.OcrMode.SINGLE_WORD)
# pylint: disable=W0212
if stbt._tesseract_version() < distutils.version.LooseVersion('3.03'):
raise SkipTest('tesseract is too old')
# Now the real test:
eq_(u'UJJM2LGE', stbt.ocr(
frame=cv2.imread('tests/ocr/UJJM2LGE.png'),
mode=stbt.OcrMode.SINGLE_WORD,
tesseract_user_patterns=[r'\n\n\n\n\n\n\n\n']))
示例10: read_hex
def read_hex(region, frame_=frame):
return stbt.ocr(
frame_,
region,
stbt.OcrMode.SINGLE_LINE,
tesseract_config={"tessedit_char_whitelist": "#0123456789abcdef"},
tesseract_user_patterns=["#\n\n\n\n\n\n"],
).replace(" ", "")
示例11: test_tesseract_user_patterns
def test_tesseract_user_patterns(patterns):
# pylint:disable=protected-access
if _tesseract_version() < LooseVersion('3.03'):
raise SkipTest('tesseract is too old')
# Now the real test:
assert u'192.168.10.1' == stbt.ocr(
frame=load_image('ocr/192.168.10.1.png'),
mode=stbt.OcrMode.SINGLE_WORD,
tesseract_user_patterns=patterns)
示例12: _read_text
def _read_text(self, title, patterns=None):
title = stbt.match_text(
title, frame=self._frame,
region=stbt.Region(x=620, y=145, right=950, bottom=460),
text_color=(124, 94, 114))
if not title:
stbt.debug("NetworkAbout: Didn't find %r" % title)
return None
region = title.region.right_of().extend(x=10, y=-5, bottom=10)
return stbt.ocr(self._frame, region, tesseract_user_patterns=patterns)
示例13: text
def text(self):
if self._text is None and self.__nonzero__():
diff = cv2.cvtColor(
cv2.absdiff(
crop(self._frame, self.region),
numpy.repeat(self._background, self.region.width, 1)),
cv2.COLOR_BGR2GRAY)
self._text = stbt.ocr(diff)
stbt.debug("Selection text: %s" % self._text)
return self._text
示例14: test_that_passing_patterns_helps_reading_serial_codes
def test_that_passing_patterns_helps_reading_serial_codes():
# pylint: disable=W0212
if _stbt.core._tesseract_version() < distutils.version.LooseVersion('3.03'):
raise SkipTest('tesseract is too old')
# Now the real test:
assert u'UJJM2LGE' == stbt.ocr(
frame=cv2.imread('tests/ocr/UJJM2LGE.png'),
mode=stbt.OcrMode.SINGLE_WORD,
tesseract_user_patterns=[r'\n\n\n\n\n\n\n\n'])
示例15: test_that_match_all_can_be_used_with_ocr_to_read_buttons
def test_that_match_all_can_be_used_with_ocr_to_read_buttons():
# Demonstrates how match_all can be used with ocr for UIs consisting of text
# on buttons
frame = _imread('buttons.png')
button = _imread('button.png')
text = [
stbt.ocr(frame=cv2.absdiff(_crop(frame, m.region), button))
for m in stbt.match_all(
button, frame=frame, match_parameters=mp(confirm_method='none'))]
text = sorted([t for t in text if t not in ['', '\\s']])
print text
assert text == [u'Button 1', u'Button 2', u'Buttons']