• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stbt.ocr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stbt.ocr函数的典型用法代码示例。如果您正苦于以下问题:Python ocr函数的具体用法?Python ocr怎么用?Python ocr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ocr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:rinaldomerlo,项目名称:stb-tester,代码行数:7,代码来源:test_ocr.py


示例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'])
开发者ID:Winnetou,项目名称:stb-tester,代码行数:9,代码来源:test_ocr.py


示例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)
开发者ID:stb-tester,项目名称:stb-tester,代码行数:9,代码来源:test_ocr.py


示例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')))
开发者ID:Winnetou,项目名称:stb-tester,代码行数:11,代码来源:test_ocr.py


示例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"
开发者ID:stb-tester,项目名称:stb-tester,代码行数:11,代码来源:test_ocr.py


示例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)
开发者ID:stb-tester,项目名称:stb-tester,代码行数:14,代码来源:test_ocr.py


示例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)
开发者ID:rinaldomerlo,项目名称:stb-tester,代码行数:7,代码来源:test_ocr.py


示例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)
开发者ID:stb-tester,项目名称:stb-tester,代码行数:28,代码来源:test_frameobject.py


示例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']))
开发者ID:Winnetou,项目名称:stb-tester,代码行数:16,代码来源:test_ocr.py


示例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(" ", "")
开发者ID:Navaneethsen,项目名称:stb-tester,代码行数:8,代码来源:stbt-camera-calibrate.py


示例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)
开发者ID:stb-tester,项目名称:stb-tester,代码行数:10,代码来源:test_ocr.py


示例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)
开发者ID:stb-tester,项目名称:stb-tester-test-pack,代码行数:10,代码来源:roku.py


示例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
开发者ID:digideskio,项目名称:stb-tester-test-pack,代码行数:10,代码来源:utils.py


示例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'])
开发者ID:LewisHaley,项目名称:stb-tester,代码行数:10,代码来源:test_ocr.py


示例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']
开发者ID:bowenyang295583341,项目名称:stb-tester,代码行数:13,代码来源:test_match.py


示例16: 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 = stbt.load_image('buttons.png')

    text = [
        stbt.ocr(frame=stbt.crop(
            frame,
            m.region.extend(x=30, y=10, right=-30, bottom=-10)))
        for m in stbt.match_all('button-transparent.png', frame=frame)]
    text = sorted([t for t in text if t not in ['', '\\s']])
    print text
    assert text == [u'Button 1', u'Button 2', u'Buttons']
开发者ID:stb-tester,项目名称:stb-tester,代码行数:13,代码来源:test_match.py


示例17: test_that_ligatures_and_ambiguous_punctuation_are_normalised

def test_that_ligatures_and_ambiguous_punctuation_are_normalised():
    frame = load_image('ocr/ambig.png')
    text = stbt.ocr(frame)
    for bad, good in [
            # tesseract 3.02
            ("horizonta|", "horizontal"),
            # tesseract 4.00 with tessdata 590567f
            ("siIIyness", "sillyness"),
            ("Iigatures", "ligatures"),
    ]:
        text = text.replace(bad, good)
    assert ligature_text == text
    assert stbt.match_text("em-dash,", frame)
    assert stbt.match_text(u"em\u2014dash,", frame)
开发者ID:stb-tester,项目名称:stb-tester,代码行数:14,代码来源:test_ocr.py


示例18: message

 def message(self):
     """
     This property demonstrates an advantage of Frame Objects over
     stand-alone helper functions. We are using the position of the "info"
     icon to find this message. Because the private ``_info`` property is
     shared between this property and ``is_visible`` we don't need to
     compute it twice -- the ``FrameObject`` base class will remember the
     value from the first time it was computed.
     """
     right_of_info = stbt.Region(
         x=self._info.region.right, y=self._info.region.y,
         width=390, height=self._info.region.height)
     return stbt.ocr(region=right_of_info, frame=self._frame) \
                .replace('\n', ' ')
开发者ID:stb-tester,项目名称:stb-tester,代码行数:14,代码来源:test_frameobject.py


示例19: check

def check(imgname, phrases, params):
    from stbt import ocr

    img = cv2.imread(imgname)
    if img is None:
        raise IOError('No such file or directory "%s"' % imgname)
    text = ocr(img, **params)

    matches = sum(1 for x in phrases if x in text)

    return {
        "matches": matches,
        "total": len(phrases),
        "percentage": float(matches) / len(phrases) * 100,
        "name": os.path.basename(imgname),
        "path": imgname,
        "phrases": [{"text": x, "match": x in text} for x in phrases],
        "text": text,
    }
开发者ID:LewisHaley,项目名称:stb-tester,代码行数:19,代码来源:validate-ocr.py


示例20: test_that_ligatures_and_ambiguous_punctuation_are_normalised

def test_that_ligatures_and_ambiguous_punctuation_are_normalised():
    text = stbt.ocr(frame=cv2.imread('tests/ocr/ambig.png'))
    text = text.replace("horizonta|", "horizontal")  # for tesseract < 3.03
    eq_(ligature_text, text)
开发者ID:Winnetou,项目名称:stb-tester,代码行数:4,代码来源:test_ocr.py



注:本文中的stbt.ocr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.Utils类代码示例发布时间:2022-05-27
下一篇:
Python stbt.match_text函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap