Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def myWaitWhileMatchText(text,
                         region=stbt.Region.ALL,
                         maxAttempts=30,
                         sleepTime=1):
    counter = 0
    result = stbt.match_text(text, None, region)
    while result.match == True and counter <= maxAttempts:
        time.sleep(sleepTime)
        counter += 1
        result = stbt.match_text(text, None, region)
    if counter > maxAttempts:
        return -1
    return 0
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
def myPressUntilMatchText(text,
                          key,
                          region=stbt.Region.ALL,
                          maxPresses=maxPressesInMainMenu):
    counter = 0
    time.sleep(sleepTimeBeforeOCR)
    result = stbt.match_text(text, None, region)
    while result.match == False and counter <= maxPresses:
        stbt.press(key, timeBeforePress)
        time.sleep(sleepTimeBeforeOCR)
        result = stbt.match_text(text, None, region)
        counter += 1
    if counter > maxPresses:
        return -1
    return 0
Ejemplo n.º 9
0
 def sprawdzSiec(self):
     ipTestResult = stbt.match_text(
         "172.016", None, stbt.Region(580, 209, width=114, height=28))
     if ipTestResult == False:
         self.testsResults["ethernet"] = False
     else:
         self.testsResults["ethernet"] = True
Ejemplo n.º 10
0
 def sprawdzGrupe(self):
     result = stbt.match_text("0", None,
                              stbt.Region(580, 490, width=35, height=28))
     if result == True:
         self.testResults["group"] = True
     else:
         self.testResults["group"] = False
Ejemplo n.º 11
0
def test_that_match_text_still_returns_if_region_doesnt_intersect_with_frame(
        region):
    frame = load_image("ocr/menu.png")
    result = stbt.match_text("Onion Bhaji", frame=frame, region=region)
    assert result.match is False
    assert result.region is None
    assert result.text == "Onion Bhaji"
Ejemplo n.º 12
0
def test_that_match_text_still_returns_if_region_doesnt_intersect_with_frame():
    frame = cv2.imread("tests/ocr/menu.png")
    result = stbt.match_text("Onion Bhaji", frame=frame,
                             region=stbt.Region(1280, 0, 1280, 720))
    assert result.match is False
    assert result.region is None
    assert result.text == "Onion Bhaji"
Ejemplo n.º 13
0
 def sprawdzWiadomosci(self):
     result = stbt.match_text("Nie", None,
                              stbt.Region(149, 504, width=42, height=26))
     if result.match == True:
         self.testResults["messages"] = True
     else:
         self.testResults["messages"] = False
Ejemplo n.º 14
0
def test_match_text_stringify_result():
    frame = load_image("ocr/menu.png")
    result = stbt.match_text(u"Onion Bhaji", frame=frame)

    assert re.match(
        r"TextMatchResult\(time=None, match=True, region=Region\(.*\), "
        r"frame=<1280x720x3>, text=u?'Onion Bhaji'\)", str(result))
Ejemplo n.º 15
0
def test_that_text_region_is_correct_even_with_regions_larger_than_frame():
    frame = cv2.imread("tests/ocr/menu.png")
    text, region, _ = list(iterate_menu())[6]
    result = stbt.match_text(
        text, frame=frame, region=region.extend(right=+12800))
    assert result
    assert region.contains(result.region)
Ejemplo n.º 16
0
def test_that_match_text_gives_tesseract_a_hint():
    frame = load_image("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)
Ejemplo n.º 17
0
def test_that_text_region_is_correct_even_with_regions_larger_than_frame():
    frame = cv2.imread("tests/ocr/menu.png")
    text, region, _ = list(iterate_menu())[6]
    result = stbt.match_text(
        text, frame=frame, region=region.extend(right=+12800))
    assert result
    assert region.contains(result.region)
Ejemplo n.º 18
0
def test_that_match_text_still_returns_if_region_doesnt_intersect_with_frame(
        region):
    frame = load_image("ocr/menu.png")
    result = stbt.match_text("Onion Bhaji", frame=frame, region=region)
    assert result.match is False
    assert result.region is None
    assert result.text == "Onion Bhaji"
Ejemplo n.º 19
0
def test_match_text_stringify_result():
    frame = cv2.imread("tests/ocr/menu.png")
    result = stbt.match_text(u"Onion Bhaji", frame=frame)

    assert re.match(
        r"TextMatchResult\(timestamp=None, match=True, region=Region\(.*\), "
        r"frame=1280x720x3, text=u'Onion Bhaji'\)", str(result))
Ejemplo n.º 20
0
 def sprawdzUSB(self):
     result = stbt.match_text("USB", None,
                              stbt.Region(696, 121, width=90, height=54))
     if result.match == False:
         self.testsResults["usb"] = False
     else:
         self.testsResults["usb"] = True
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
 def is_visible(self):
     return stbt.match_text("Exit?",
                            frame=self._frame,
                            region=stbt.Region(x=270,
                                               y=240,
                                               right=1000,
                                               bottom=320))
Ejemplo n.º 23
0
def test_match_text_stringify_result():
    frame = cv2.imread("tests/ocr/menu.png")
    result = stbt.match_text(u"Onion Bhaji", frame=frame)

    assert re.match(
        r"TextMatchResult\(timestamp=None, match=True, region=Region\(.*\), "
        r"frame=1280x720x3, text=u'Onion Bhaji'\)", str(result))
Ejemplo n.º 24
0
def test_that_match_text_still_returns_if_region_doesnt_intersect_with_frame():
    frame = cv2.imread("tests/ocr/menu.png")
    result = stbt.match_text("Onion Bhaji", frame=frame,
                             region=stbt.Region(1280, 0, 1280, 720))
    assert result.match is False
    assert result.region is None
    assert result.text == "Onion Bhaji"
Ejemplo n.º 25
0
 def sprawdzHDD(self):
     stbt.press("KEY_REC", Test.timeBeforePress)
     time.sleep(120)
     stbt.press("KEY_STOP", Test.timeBeforePress)
     stbt.press("KEY_OK", Test.timeBeforePress)
     stbt.press("KEY_LIST", Test.timeBeforePress)
     today = stbt.ocr(None, stbt.Region(1055, 45, width=80, height=30),
                      stbt.OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD)
     recordingDate = ocr(None, stbt.Region(660, 200, width=80, height=30),
                         stbt.OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD)
     if recordingDate == today:
         stbt.press("KEY_PLAY", Test.timeBeforePress)
         time.sleep(10)
         stbt.press("KEY_PAUSE", Test.timeBeforePress)
         try:
             stbt.wait_for_motion(timeout_sec=3,
                                  region=stbt.Region(10,
                                                     100,
                                                     width=1200,
                                                     height=400))
         except MotionTimeout:
             stbt.press("KEY_PLAY", Test.timeBeforePress)
             stbt.press("KEY_FWD", Test.timeBeforePress)
             result = stbt.match_text(
                 "x1,5", None, stbt.Region(110, 610, width=160, height=30))
             if result:
                 for i in range(3):
                     stbt.press("KEY_REV", Test.timeBeforePress)
                 result = stbt.match_text(
                     "x2,0", None,
                     stbt.Region(110, 610, width=160, height=30))
                 if result:
                     selft.testsResults["hdd"] = True
                 else:
                     self.testsResults["hdd"] = False
             else:
                 self.testsResults["hdd"] = False
         else:
             self.testsResults["hdd"] = False
         stbt.press("KEY_STOP", Test.timeBeforePress)
         stbt.press("KEY_RED", Test.timeBeforePress)
         stbt.press("KEY_LEFT", Test.timeBeforePress)
         stbt.press("KEY_OK", Test.timeBeforePress)
     else:
         self.testsResults["hdd"] = False
     stbt.press("KEY_LIST", Test.timeBeforePress)
Ejemplo n.º 26
0
def test_match_text_stringify_result():
    frame = load_image("ocr/menu.png")
    result = stbt.match_text(u"Onion Bhaji", frame=frame)

    assert re.match(
        r"TextMatchResult\(time=None, match=True, region=Region\(.*\), "
        r"frame=<1280x720x3>, text=u'Onion Bhaji'\)",
        str(result))
Ejemplo n.º 27
0
 def sprawdzUSB(self, port):
     result = stbt.match_text("USB", None,
                              stbt.Region(682, 162, width=70, height=28))
     if result.match == True:
         stbt.press("KEY_RIGHT", Test.timeBeforePress)
         stbt.press("KEY_OK", Test.timeBeforePress)
         self.testsResults[port] = True
     else:
         self.testsResults[port] = False
Ejemplo n.º 28
0
def test_that_match_text_still_returns_if_region_doesnt_intersect_with_frame(
        region):
    frame = load_image("ocr/menu.png")
    result = stbt.match_text("Onion Bhaji", frame=frame, region=region)
    assert result.match is False
    assert result.region is None
    assert result.text == "Onion Bhaji"

    # Avoid future.types.newtypes in return values
    assert type(result.text).__name__ in ["str", "unicode"]
Ejemplo n.º 29
0
 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)
Ejemplo n.º 30
0
 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)
Ejemplo n.º 31
0
def sprawdzSiec():
    ipTestResult = stbt.match_text("172.16", None,
                                   stbt.Region(707, 297, width=66, height=27))
    if ipTestResult == False:
        return -1
    stbt.press("KEY_INFO", timeBeforePress)
    stbt.press("KEY_DOWN", timeBeforePress)
    stbt.press("KEY_OK", timeBeforePress)
    time.sleep(sleepTimeBeforeOCR)
    wifiLevel = stbt.ocr(None, stbt.Region(1110, 281, width=58, height=35),
                         stbt.OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD)
    wl = wifiLevel[:-1]
    i = int(wl)
    print("Odczytana sila sygnalu WiFi: ", i)
    if i < minWiFiSignalLevel:
        return -2
    return 0
Ejemplo n.º 32
0
 def test(text, region):
     result = stbt.match_text(text, frame=frame)
     assert result
     assert region.contains(result.region)  # pylint: disable=E1101
Ejemplo n.º 33
0
 def match_text():
     return stbt.match_text("RED", frame=frame)
Ejemplo n.º 34
0
def test_that_match_text_accepts_unicode():
    f = cv2.imread("tests/ocr/unicode.png")
    assert stbt.match_text("David", f, lang='eng+deu')  # ascii
    assert stbt.match_text(u"Röthlisberger", f, lang='eng+deu')  # unicode
    assert stbt.match_text("Röthlisberger", f, lang='eng+deu')  # utf-8 bytes
Ejemplo n.º 35
0
def test_match_text_on_single_channel_image():
    frame = cv2.imread("tests/ocr/menu.png", cv2.IMREAD_GRAYSCALE)
    assert stbt.match_text("Onion Bhaji", frame)
Ejemplo n.º 36
0
def test_match_text_case_sensitivity():
    frame = cv2.imread("tests/ocr/menu.png", cv2.IMREAD_GRAYSCALE)
    assert stbt.match_text("ONION BHAJI", frame)
    assert stbt.match_text("ONION BHAJI", frame, case_sensitive=False)
    assert not stbt.match_text("ONION BHAJI", frame, case_sensitive=True)
Ejemplo n.º 37
0
 def test(text, region, upsample):
     result = stbt.match_text(text, frame=frame, upsample=upsample)
     assert result
     assert region.contains(result.region)  # pylint:disable=no-member
Ejemplo n.º 38
0
def test_ocr_debug():
    # So that the output directory name doesn't depend on how many tests
    # were run before this one.
    ImageLogger._frame_number = itertools.count(1)  # pylint:disable=protected-access

    f = stbt.load_image("action-panel.png")
    r = stbt.Region(0, 370, right=1280, bottom=410)
    c = (235, 235, 235)
    nonoverlapping = stbt.Region(2000, 2000, width=10, height=10)

    with scoped_curdir(), scoped_debug_level(2):

        stbt.ocr(f)
        stbt.ocr(f, region=r)
        stbt.ocr(f, region=r, text_color=c)
        stbt.ocr(f, region=nonoverlapping)

        stbt.match_text("Summary", f)  # no match
        stbt.match_text("Summary", f, region=r)  # no match
        stbt.match_text("Summary", f, region=r, text_color=c)
        stbt.match_text("Summary", f, region=nonoverlapping)

        files = subprocess.check_output("find stbt-debug | sort", shell=True)
        assert files == dedent("""\
            stbt-debug
            stbt-debug/00001
            stbt-debug/00001/index.html
            stbt-debug/00001/source.png
            stbt-debug/00001/tessinput.png
            stbt-debug/00001/upsampled.png
            stbt-debug/00002
            stbt-debug/00002/index.html
            stbt-debug/00002/source.png
            stbt-debug/00002/tessinput.png
            stbt-debug/00002/upsampled.png
            stbt-debug/00003
            stbt-debug/00003/index.html
            stbt-debug/00003/source.png
            stbt-debug/00003/tessinput.png
            stbt-debug/00003/text_color_difference.png
            stbt-debug/00003/text_color_threshold.png
            stbt-debug/00003/upsampled.png
            stbt-debug/00004
            stbt-debug/00004/index.html
            stbt-debug/00004/source.png
            stbt-debug/00005
            stbt-debug/00005/index.html
            stbt-debug/00005/source.png
            stbt-debug/00005/tessinput.png
            stbt-debug/00005/upsampled.png
            stbt-debug/00006
            stbt-debug/00006/index.html
            stbt-debug/00006/source.png
            stbt-debug/00006/tessinput.png
            stbt-debug/00006/upsampled.png
            stbt-debug/00007
            stbt-debug/00007/index.html
            stbt-debug/00007/source.png
            stbt-debug/00007/tessinput.png
            stbt-debug/00007/text_color_difference.png
            stbt-debug/00007/text_color_threshold.png
            stbt-debug/00007/upsampled.png
            stbt-debug/00008
            stbt-debug/00008/index.html
            stbt-debug/00008/source.png
            """)
Ejemplo n.º 39
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.º 40
0
 def match_text():
     return stbt.match_text("RED", frame=frame)
Ejemplo n.º 41
0
def test_match_text_case_sensitivity():
    frame = load_image("ocr/menu.png", cv2.IMREAD_GRAYSCALE)
    assert stbt.match_text("ONION BHAJI", frame)
    assert stbt.match_text("ONION BHAJI", frame, case_sensitive=False)
    assert not stbt.match_text("ONION BHAJI", frame, case_sensitive=True)
Ejemplo n.º 42
0
def test_that_roku_home_says_streaming_channels():
    stbt.press('KEY_HOME')
    assert stbt.wait_until(lambda: stbt.match_text("Streaming Channels"))
Ejemplo n.º 43
0
def test_match_text_on_single_channel_image():
    frame = load_image("ocr/menu.png", cv2.IMREAD_GRAYSCALE)
    assert stbt.match_text("Onion Bhaji", frame)
Ejemplo n.º 44
0
 def sprawdzSiec(self):
     ipTestResult = stbt.match_text("172.16", None, stbt.Region(x=655, y=233, width=56, height=24))
     if  ipTestResult == False:
Ejemplo n.º 45
0
def test_that_match_text_returns_no_match_for_non_matching_text():
    frame = load_image("ocr/menu.png")
    assert not stbt.match_text(u"Noodle Soup", frame=frame)
Ejemplo n.º 46
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.º 47
0
    def testAutodiag(self):
        scanedSN #zeskanowany SN dekodera
        self.sprawdzSN(scannedSN)
        stbt.press("KEY_OK", Test.timeBeforePress)
        for i in range(10):
            result = stbt.match_text("OK", None, stbt.Region(x=665, y=293 + 16 * i, width=30, height=16))
            if result == False:
                self.testsResults["hds_autodiag_hardware_test"] = False
                return
        stbt.prsss("KEY_DOWN", Test.timeBeforePress)
        for i in range(3):
            result = stbt.match_text("OK", None, stbt.Region(x=665, y=293 + 16 * i, width=30, height=16))
            if result == False:
                self.testsResults["hds_autodiag_hardware_test"] = False
                return
        stbt.press("KEY_MENU",  Test.timeBeforePress)
        stbt.press_until_match("KEY_DOWN", "./images/t1/hds_hard_disk.png", self.timeBeforePress, 5, region = stbt.Region(x=464, y=357, width=117, height=13))
        stbt.press("KEY_OK", Test.timeBeforePress)
        stbt.press("KEY_OK", Test.timeBeforePress)
        result = stbt.match_text("PASS")
        if result == False:
            self.testsResults["hdd"] = False
            return
        stbt.press("KEY_MENU",  Test.timeBeforePress)
        stbt.press("KEY_DOWN", Test.timeBeforePress)
        stbt.press("KEY_OK", Test.timeBeforePress)
        stbt.press("KEY_OK", Test.timeBeforePress)
        while True:
            time.sleep(2)
            if stbt.match_text("PASS", region = stbt.Region(x=663, y=290, width=70, height=20)):
                self.testsResults["hdd"] = True
                break
            elif stbt.match_text("FAIL", region = stbt.Region(x=663, y=290, width=70, height=20)):
                self.testsResults["hdd"] = False
                return
        stbt.press("KEY_MENU", Test.timeBeforePress)
        stbt.press("KEY_DOWN", Test.timeBeforePress)
        stbt.press("KEY_DOWN", Test.timeBeforePress)
        stbt.press("KEY_OK", Test.timeBeforePress)
        self.typeAutodiagPassword()
        while True:
            time.sleep(2)
            if stbt.match_text("PASS", region = stbt.Region(x=663, y=290, width=70, height=20)):
                self.testsResults["hdd"] = True
                break
            elif stbt.match_text("FAIL", region = stbt.Region(x=663, y=290, width=70, height=20)):
                self.testsResults["hdd"] = False
                return
        stbt.press("KEY_MENU", Test.timeBeforePress)
        stbt.press("KEY_MENU", Test.timeBeforePress)
        stbt.press_until_match("KEY_DOWN", "./images/t1/hds_autodiag_factory_settings.png", Test.timeBeforePress, 5, region = stbt.Region(x=464, y=371, width=212, height=21))
        stbt.press("KEY_OK", Test.timeBeforePress)
        self.typeAutodiagPassword()
        stbt.press("KEY_OK", Test.timeBeforePress)
        stbt.press("KEY_DOWN", Test.timeBeforePress)
        stbt.press("KEY_DOWN", Test.timeBeforePress)
        stbt.press("KEY_OK", Test.timeBeforePress)
        while True:
            time.sleep(2)
            if stbt.match_text("DONE", region = stbt.Region(x=637, y=292, width=78, height=14))):
                while True:
                    time.sleep(1)
                    if stbt.match_text("DONE", region = stbt.Region(x=636, y=309, width=70, height=14):
                        self.testsResults["hds_factory_settings"] = True
                        break
                    elif stbt.match_text("FAIL", region = stbt.Region(x=636, y=309, width=70, height=14):
                        self.testsResults["hds_factory_settings"] = False
                        return
                break
            elif stbt.match_text("FAIL", region = stbt.Region(x=637, y=292, width=78, height=14)):
                self.testsResults["hds_factory_settings"] = False
                return
        stbt.press("KEY_MENU", Test.timeBeforePress)
        stbt.press("KEY_MENU", Test.timeBeforePress)

    def wejdzWUstawienia(self):
        stbt.press("KEY_MENU", self.timeBeforePress)
        self.myPressUntilMatchText("USTAWIENIA", "KEY_RIGHT", stbt.Region(x=550, y=605, width=180, height=41), 10)
        stbt.press("KEY_OK", self.timeBeforePress)

    def typeAutodiagPassword(self):
        stbt.press("KEY_5", Test.timeBeforePress)
        stbt.press("KEY_5", Test.timeBeforePress)
        stbt.press("KEY_5", Test.timeBeforePress)

    def sprawdzRachunki(self):
        result = stbt.match_text("BRAK", None, stbt.Region(x=845, y=235, width=72, height=26))
        if result:
            self.testsResults["bills"] = True
        else:
            self.testsResults["bills"] = False

    def sprawdzWiadomosci(self):
        result = stbt.ocr(region = stbt.Region(x=101, y=135, width=1075, height=32))
        if result == "":
            self.testsResults["messages"] = True
        else:
            self.testsResults["messages"] = False

    def sprawdzHDD(self):
        today = stbt.ocr(region = stbt.Region(x=1026, y=35, width=86, height=33))
        recordingDate = ocr(region = stbt.Region(x=673, y=543, width=62, height=22))
        if recordingDate == today:
            stbt.press("KEY_PLAY", Test.timeBeforePress)
            time.sleep(10)
            stbt.press("KEY_PAUSE", Test.timeBeforePress)
            try:
                stbt.wait_for_motion(timeout_sec = 3, region = stbt.Region(x=10, y=11, width=1260, height=540))
            except MotionTimeout:
                stbt.press("KEY_REV", Test.timeBeforePress)
                if stbt.match_text("x4", region = stbt.Region(x=186, y=588, width=30, height=21)):
                    stbt.press("KEY_FWD", Test.timeBeforePress)
                    stbt.press("KEY_FWD", Test.timeBeforePress)
                    if stbt.match_text("x8", region = stbt.Region(x=186, y=588, width=30, height=21)):
                        selft.testsResults["hdd"] = True
                    else:
                        self.testsResults["hdd"] = False
                else:
                    self.testsResults["hdd"] = False
            else:
                self.testsResults["hdd"] = False
            stbt.press("KEY_STOP", Test.timeBeforePress)
            stbt.press("KEY_3", Test.timeBeforePress)
            stbt.press("KEY_OK", Test.timeBeforePress)
        else:
            self.testsResults["hdd"] = False

    def sprawdzSN(self, scannedSN):
        SN = stbt.ocr(region = stbt.Region(x=600, y=251, width=164, height=19))
        print("Odczytany SN: ", SN)  
        if SN != scannedSN:
            self.testsResults["sn"] = False
        else:
            self.testsResults["sn"] = True

    def sprawdzCzytnikKart(self):
        print("Wloz karte do czytnika.")
        result = myWaitWhileMatchText("BRAK KARTY", stbt.Region(x=555, y=127, width=165, height=33))
        if result:
            result = stbt.match("./images/t1/hds_smart_card_error.png", region = stbt.Region(x=555, y=127, width=165, height=33))
            if result:
                self.testsResults["card_reader"] = False
            else:
                self.testsResults["card_reader"] = True
        else:
            self.testsResults["card_reader"] = False

    def sprawdzMaxIndex(self):
        maxIndex = stbt.ocr(region = stbt.Region(x=669, y=418, width=56, height=35)) #stbt.ocr(None, stbt.Region(x=669, y=418, width=56, height=35), stbt.OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD)
        if maxIndex == "0":
            self.testsResults["max_index"] = True
        else:
            self.testsResults["max_index"] = False

    def sprawdzSiec(self):
        ipTestResult = stbt.match_text("172.16", None, stbt.Region(x=655, y=233, width=56, height=24))
        if  ipTestResult == False:
            self.testsResults["ethernet"] = False
        else:
            self.testsResults["ethernet"] = True

    def sprawdzWersjeOprogramowania(self):
        softVersion = stbt.ocr(region = stbt.Region(x=811, y=323, width=47, height=21)) #stbt.ocr(None, stbt.Region(x=811, y=323, width=47, height=21), stbt.OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD)
        if softVersion == currentUpdateVersions[0]uv or softVersion == currentUpdateVersions[1]:
            self.testsResults["soft_version"] = True
        else:
            self.testsResults["soft_version"] = False

    def sprawdzSileIJakosSygnalu(self):
        self.testsResults["signal_level"] = stbt.match("./images/t1/hds_signal_level.png", region = stbt.Region(x=743, y=324, width=111, height=19))

    def sprawdzUSB(self, port):
        print("Wloz Pendrive do gniazda USB umieszczonego z boku.")
        input = input("Czy dioda Pendrive swieci?\n1) Tak\n2) Nie")
        while input != "1" and input  != "2":
            input = input("Czy dioda Pendrive swieci?\n1) Tak\n2) Nie")
        if input == "1":
            self.testsResults[port] = True
        else:
            self.testsResults[port] = False

    def sprawdzTimeshifting(self):
        stbt.press("KEY_PAUSE", Test.timeBeforePress)
        try:
            stbt.wait_for_motion(timeout_sec = 3, region = stbt.Region(x=10, y=70, width=1260, height=480))
        except MotionTimeout:
            stbt.press("KEY_STOP", Test.timeBeforePress)
            try:
                stbt.wait_for_motion()
            except MotionTimeout:
                self.testsResults["timeshifting"] = False
            else:
                self.testsResults["timeshifting"] = True
        else:
            self.testsResults["timeshifting"] = False

    def sprawdzWyswietlacz(self):
        self.runChannel("888")
        input = input("Czy wyswietlacz swieci prawidlowo?\n1) Tak\n2) Nie")
        while input != "1" and input  != "2":
            input = input("Czy wyswietlacz swieci prawidlowo?\n1) Tak\n2) Nie")
        if input == "1":
            self.testsResults["display"] = True
        else
            self.testsResults["dispaly"] = False

    def sprawdzTVNaziemna(self):
        self.runChannel("998")
        input = input("Czy obraz na ekranie wyswietlany jest prawidlowo?\n1) Tak\n2) Nie")
        while input != "1" and input != "2":
            input = input("Czy obraz na ekranie wyswietlany jest prawidlowo?\n1) Tak\n2) Nie")
        if input == "1":
            self.testsResults["terrestrial_siganl_quality"] = True
        else:
            self.runChannel("994")
            input = input("Czy obraz na ekranie wyswietlany jest prawidlowo?\n1) Tak\n2) Nie")
            while input != "1" and input != "2":
                input = input("Czy obraz na ekranie wyswietlany jest prawidlowo?\n1) Tak\n2) Nie")
            if input == "1":
                self.testsResults["terrestrial_siganl_quality"] = True
            else:
                self.testsResults["terrestrial_siganl_quality"] = False
    
    def sprawdzPrzyciski(self, maxAttempts = 5):
        result = {}
        counter = 0
        print("Wcisnij kalwisz P-")
        detection = channelSwitchDetection(self.mainTestChannels[0])
        while detection[0] != 1 and counter < maxAttempts:
            detection = channelSwitchDetection(self.mainTestChannels[0])
            counter += 1
        if counter == maxAttempts:
            result["P-"] = False
        else:
            result["P-"] = True
        time.sleep(5)
        print("Wciśnij klawisz 'P+'")
        counter = 0
        detection = channelSwitchDetection(detection[1])
        while detection[0] != 2 and counter < maxAttempts:
            detection = channelSwitchDetection(detection[1])
            counter += 1
        if counter == maxAttempts:
            result["P+"] = False
        else:
            result["P+"] = True
        
        print("Wcisnij klawisz 'V+'")
        result["V+"] = self.volumeUpSwitchDetection()

        print("Wcisnij klawisz 'V-'")
        result["V-"] = self.volumeDownSwitchDetection()

        time.sleep(5)
        print("Wcisnij klawisz 'St-By'")
        counter = 0
        detection = stbySwitchDetection()
        while detection == False and counter < maxAttempts:
            detection = stbySwitchDetection()
            counter += 1
        if counter == maxAttempts:
            result["St-By"] = False
        else:
            result["St-By"] = True

        self.testsResults["switches"] = result

    def channelSwitchDetection(channelToCompare):
        result = [0, 0]
        try:
            stbt.wait_for_match("./images/t1/hds_up_arrow.png", region = stbt.Region(x=255, y=539, width=39, height=31)) # oczekiwanie na wcisnienie przycisku
        except stbt.MatchTimeout:
            result[0] = -1
            result[1] = channelToCompare
            return result
        channelNumber = stbt.ocr(None, stbt.Region(90, 592, width=45, height=41), stbt.OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD)
        cn = int(channelNumber)
        result[1] = cn
        if cn < channelToCompare:
            result[0] = 1
        elif cn > channelToCompare:
            result[0] = 2
        return result

    def stbySwitchDetection(maxAttempts = 5, sleepTime = 1):
        counter = 0
        result = stbt.is_screen_black()
        while result.black == False and counter <= maxAttempts:
            time.sleep(sleepTime)
            result = stbt.is_screen_black()
            counter += 1
        if counter > maxAttempts:
            return False
        return True

    def volumeUpSwitchDetection(self):
        try:
            stbt.wait_for_match("./images/t1/hds_max_volume_belt.png", region = stbt.Region(x=178, y=94, width=118, height=16))
        except stbt.MatchTimeout: 
            return False
        return True

    def volumeDownSwitchDetection(self):
        try:
            stbt.wait_for_match("./hds_part_volume_belt.png", region = stbt.Region(x=178, y=94, width=64, height=16))
        except stbt.MatchTimeout:
            return False
        else
            if stbt.match("./images/t1/hds_max_volume_belt.png", region = stbt.Region(x=178, y=94, width=118, height=16)):
                return False
            return True

    def lodeConfiguration(self, path):
        domeTree = minidom.parse(path)
        parameters = domeTree.firstChild # <parameters>
        paramChilds = parameters.childNodes

        soft = paramChilds[1] # <soft>
        softChilds = soft.getElementsByTagName("version")
        self.currentUpdateVersions.append(int(soft.childNodes[1].firstChild.data)) # <version>
        self.currentUpdateVersions.append(int(soft.childNodes[3].firstChild.data)) # <version>

        testChannels = paramChilds[7] # <test_channels>
        channels = testChannels.childNodes
        self.mainTestChannels.append(int(testChannels.childNodes[1].firstChild.data)) # <channel>
        self.mainTestChannels.append(int(testChannels.childNodes[3].firstChild.data)) # <channel>
        self.mainTestChannels.append(int(testChannels.childNodes[5].firstChild.data)) # <channel>
        self.mainTestChannels.append(int(testChannels.childNodes[7].firstChild.data)) # <channel>
        self.alternativeTestChannels.append(int(testChannels.childNodes[9].firstChild.data)) # <channel>
        self.alternativeTestChannels.append(int(testChannels.childNodes[11].firstChild.data)) # <channel>
        self.alternativeTestChannels.append(int(testChannels.childNodes[13].firstChild.data)) # <channel>
        self.alternativeTestChannels.append(int(testChannels.childNodes[15].firstChild.data)) # <channel>
        self.mainTerrestrialTestChannel = testChannels.childNodes[17].firstChild.data # <channel>
        self.alternativeTerrestrialTestChannel = testChannels.childNodes[19].firstChild.data # <channel>
Ejemplo n.º 48
0
 def test(text, region, upsample):
     result = stbt.match_text(text, frame=frame, upsample=upsample)
     assert result
     assert region.contains(result.region)  # pylint:disable=no-member
Ejemplo n.º 49
0
def test_that_match_text_accepts_unicode():
    f = load_image("ocr/unicode.png")
    assert stbt.match_text("David", f, lang='eng+deu')  # ascii
    assert stbt.match_text("Röthlisberger", f, lang='eng+deu')  # unicode
    assert stbt.match_text("Röthlisberger".encode('utf-8'), f,
                           lang='eng+deu')  # utf-8 bytes
Ejemplo n.º 50
0
def test_that_match_text_returns_no_match_for_non_matching_text():
    frame = cv2.imread("tests/ocr/menu.png")
    assert not stbt.match_text(u"Noodle Soup", frame=frame)
Ejemplo n.º 51
0
def test_that_match_text_returns_no_match_for_non_matching_text():
    frame = load_image("ocr/menu.png")
    assert not stbt.match_text(u"Noodle Soup", frame=frame)