def test_match_region2(x, y, offset_x, offset_y, width, height, frame_width, frame_height): if x >= 0: x = x + offset_x else: x = frame_width - width - offset_x if y >= 0: y = y + offset_y else: y = frame_height - height - offset_y region = stbt.Region(x, y, width=width, height=height) image = numpy.ones((region.height, region.width, 3), numpy.uint8) * 255 image[5:-5, 5:-5] = (255, 0, 0) frame = black(frame_width, frame_height) frame[region.to_slice()] = image[ 0 if region.y >= 0 else -region.y:region. height if region.bottom <= frame_height else frame_height - region.y, 0 if region.x >= 0 else -region.x:region. width if region.right <= frame_width else frame_width - region.x] * .85 # N.B. .85 is the lowest at which all the tests still passed when I # disabled the pyramid optimisation. should_match = _image_region(frame).contains(region) m = stbt.match(image, frame) if should_match != m.match or os.environ.get("STBT_DEBUG"): with scoped_debug_level(2): stbt.match(image, frame) assert should_match == m.match if should_match: assert m.region == region
def test_that_build_pyramid_relaxes_mask(): from _stbt.match import _build_pyramid mask = numpy.ones((200, 20, 3), dtype=numpy.uint8) * 255 mask[5:9, 5:9] = 0 # first 0 is an even row/col, last 0 is an odd row/col n = mask.size - numpy.count_nonzero(mask) assert n == 4 * 4 * 3 cv2.imwrite("/tmp/dave1.png", mask) with scoped_debug_level(2): mask_pyramid = _build_pyramid(mask, 2, is_mask=True) assert numpy.all(mask_pyramid[0] == mask) downsampled = mask_pyramid[1] cv2.imwrite("/tmp/dave2.png", downsampled) assert downsampled.shape == (98, 8, 3) print(downsampled[:, :, 0]) # pylint:disable=unsubscriptable-object # pylint:disable=bad-whitespace expected = \ [[255, 255, 255, 255, 255, 255, 255, 255], [255, 0, 0, 0, 0, 255, 255, 255], [255, 0, 0, 0, 0, 255, 255, 255], [255, 0, 0, 0, 0, 255, 255, 255], [255, 0, 0, 0, 0, 255, 255, 255]] + \ [[255, 255, 255, 255, 255, 255, 255, 255]] * 93 assert numpy.all(downsampled[:, :, 0] == expected) # pylint:disable=unsubscriptable-object
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) with scoped_curdir(), scoped_debug_level(2): stbt.ocr(f) stbt.ocr(f, region=r) stbt.ocr(f, region=r, text_color=c) 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) files = subprocess.check_output("find stbt-debug | sort", shell=True) \ .decode("utf-8") 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/00004/tessinput.png stbt-debug/00004/upsampled.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/text_color_difference.png stbt-debug/00006/text_color_threshold.png stbt-debug/00006/upsampled.png """)
def test_pyramid_roi_too_small(frame, image, match_method, match_threshold): # This is a regression test for an error that was seen with a particular # frame from a single test-run, with SQDIFF_NORMED: # cv2.error: (-215) _img.size().height <= _templ.size().height && # _img.size().width <= _templ.size().width in function matchTemplate with scoped_debug_level(2): stbt.match(image, frame=stbt.load_image(frame), match_parameters=stbt.MatchParameters( match_method=match_method, match_threshold=match_threshold))
def test_is_screen_black_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("videotestsrc-full-frame.png") with scoped_curdir(), scoped_debug_level(2): stbt.is_screen_black(f) stbt.is_screen_black(f, mask="videotestsrc-mask-non-black.png") stbt.is_screen_black(f, mask="videotestsrc-mask-no-video.png") stbt.is_screen_black(f, region=stbt.Region(0, 0, 160, 120)) files = subprocess.check_output("find stbt-debug | sort", shell=True) \ .decode("utf-8") assert files == dedent("""\ stbt-debug stbt-debug/00001 stbt-debug/00001/grey.png stbt-debug/00001/index.html stbt-debug/00001/non_black.png stbt-debug/00001/source.png stbt-debug/00002 stbt-debug/00002/grey.png stbt-debug/00002/index.html stbt-debug/00002/mask.png stbt-debug/00002/non_black.png stbt-debug/00002/source.png stbt-debug/00003 stbt-debug/00003/grey.png stbt-debug/00003/index.html stbt-debug/00003/mask.png stbt-debug/00003/non_black.png stbt-debug/00003/source.png stbt-debug/00004 stbt-debug/00004/grey.png stbt-debug/00004/index.html stbt-debug/00004/non_black.png stbt-debug/00004/source.png """) assert_expected("stbt-debug-expected-output/is_screen_black")
def test_is_screen_black_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("videotestsrc-full-frame.png") with scoped_curdir(), scoped_debug_level(2): stbt.is_screen_black(f) stbt.is_screen_black(f, mask="videotestsrc-mask-non-black.png") stbt.is_screen_black(f, mask="videotestsrc-mask-no-video.png") stbt.is_screen_black(f, region=stbt.Region(0, 0, 160, 120)) files = subprocess.check_output("find stbt-debug | sort", shell=True) assert files == dedent("""\ stbt-debug stbt-debug/00001 stbt-debug/00001/grey.png stbt-debug/00001/index.html stbt-debug/00001/non_black.png stbt-debug/00001/source.png stbt-debug/00002 stbt-debug/00002/grey.png stbt-debug/00002/index.html stbt-debug/00002/mask.png stbt-debug/00002/non_black.png stbt-debug/00002/source.png stbt-debug/00003 stbt-debug/00003/grey.png stbt-debug/00003/index.html stbt-debug/00003/mask.png stbt-debug/00003/non_black.png stbt-debug/00003/source.png stbt-debug/00004 stbt-debug/00004/grey.png stbt-debug/00004/index.html stbt-debug/00004/non_black.png stbt-debug/00004/source.png """) assert_expected("stbt-debug-expected-output/is_screen_black")
def test_motion_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 def fake_frames(): for i, f in enumerate( ["box-00001.png", "box-00002.png", "box-00003.png"]): yield stbt.Frame(stbt.load_image(f), time=i) with scoped_curdir(), scoped_debug_level(2): for _ in stbt.detect_motion(frames=fake_frames()): pass for _ in stbt.detect_motion(frames=fake_frames(), mask="box-00000.png"): pass for _ in stbt.detect_motion(frames=fake_frames(), region=stbt.Region(0, 0, 320, 400)): pass files = subprocess.check_output("find stbt-debug | sort", shell=True) assert files == dedent("""\ stbt-debug stbt-debug/00001 stbt-debug/00001/absdiff.png stbt-debug/00001/absdiff_threshold_erode.png stbt-debug/00001/absdiff_threshold.png stbt-debug/00001/gray.png stbt-debug/00001/index.html stbt-debug/00001/previous_frame_gray.png stbt-debug/00001/source.png stbt-debug/00002 stbt-debug/00002/absdiff.png stbt-debug/00002/absdiff_threshold_erode.png stbt-debug/00002/absdiff_threshold.png stbt-debug/00002/gray.png stbt-debug/00002/index.html stbt-debug/00002/previous_frame_gray.png stbt-debug/00002/source.png stbt-debug/00003 stbt-debug/00003/absdiff_masked.png stbt-debug/00003/absdiff.png stbt-debug/00003/absdiff_threshold_erode.png stbt-debug/00003/absdiff_threshold.png stbt-debug/00003/gray.png stbt-debug/00003/index.html stbt-debug/00003/mask.png stbt-debug/00003/previous_frame_gray.png stbt-debug/00003/source.png stbt-debug/00004 stbt-debug/00004/absdiff_masked.png stbt-debug/00004/absdiff.png stbt-debug/00004/absdiff_threshold_erode.png stbt-debug/00004/absdiff_threshold.png stbt-debug/00004/gray.png stbt-debug/00004/index.html stbt-debug/00004/mask.png stbt-debug/00004/previous_frame_gray.png stbt-debug/00004/source.png stbt-debug/00005 stbt-debug/00005/absdiff.png stbt-debug/00005/absdiff_threshold_erode.png stbt-debug/00005/absdiff_threshold.png stbt-debug/00005/gray.png stbt-debug/00005/index.html stbt-debug/00005/previous_frame_gray.png stbt-debug/00005/source.png stbt-debug/00006 stbt-debug/00006/absdiff.png stbt-debug/00006/absdiff_threshold_erode.png stbt-debug/00006/absdiff_threshold.png stbt-debug/00006/gray.png stbt-debug/00006/index.html stbt-debug/00006/previous_frame_gray.png stbt-debug/00006/source.png """) assert_expected("stbt-debug-expected-output/motion")
def test_match_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 with scoped_curdir(), scoped_debug_level(2): # First pass gives no matches: matches = list( stbt.match_all( "videotestsrc-redblue-flipped.png", frame=stbt.load_image("videotestsrc-full-frame.png"))) print matches assert len(matches) == 0 # Multiple matches; first pass stops with a non-match: matches = list( stbt.match_all("button.png", frame=stbt.load_image("buttons.png"), match_parameters=mp(match_threshold=0.995))) print matches assert len(matches) == 6 # Multiple matches; second pass stops with a non-match: matches = list( stbt.match_all("button.png", frame=stbt.load_image("buttons.png"))) print matches assert len(matches) == 6 # With absdiff: matches = list( stbt.match_all("button.png", frame=stbt.load_image("buttons.png"), match_parameters=mp(confirm_method="absdiff", confirm_threshold=0.16))) print matches assert len(matches) == 6 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/level2-source_matchtemplate.png stbt-debug/00001/level2-source.png stbt-debug/00001/level2-source_with_match.png stbt-debug/00001/level2-source_with_rois.png stbt-debug/00001/level2-template.png stbt-debug/00001/match0-heatmap.png stbt-debug/00001/match0-source_with_match.png stbt-debug/00001/source.png stbt-debug/00001/source_with_matches.png stbt-debug/00001/template.png stbt-debug/00002 stbt-debug/00002/index.html stbt-debug/00002/level0-source_matchtemplate.png stbt-debug/00002/level0-source_matchtemplate_threshold.png stbt-debug/00002/level0-source.png stbt-debug/00002/level0-source_with_match.png stbt-debug/00002/level0-source_with_rois.png stbt-debug/00002/level0-template.png stbt-debug/00002/level1-source_matchtemplate.png stbt-debug/00002/level1-source_matchtemplate_threshold.png stbt-debug/00002/level1-source.png stbt-debug/00002/level1-source_with_match.png stbt-debug/00002/level1-source_with_rois.png stbt-debug/00002/level1-template.png stbt-debug/00002/level2-source_matchtemplate.png stbt-debug/00002/level2-source_matchtemplate_threshold.png stbt-debug/00002/level2-source.png stbt-debug/00002/level2-source_with_match.png stbt-debug/00002/level2-source_with_rois.png stbt-debug/00002/level2-template.png stbt-debug/00002/match0-confirm-absdiff.png stbt-debug/00002/match0-confirm-absdiff_threshold_erode.png stbt-debug/00002/match0-confirm-absdiff_threshold.png stbt-debug/00002/match0-confirm-source_roi_gray_normalized.png stbt-debug/00002/match0-confirm-source_roi_gray.png stbt-debug/00002/match0-confirm-source_roi.png stbt-debug/00002/match0-confirm-template_gray_normalized.png stbt-debug/00002/match0-confirm-template_gray.png stbt-debug/00002/match0-heatmap.png stbt-debug/00002/match0-source_with_match.png stbt-debug/00002/match1-confirm-absdiff.png stbt-debug/00002/match1-confirm-absdiff_threshold_erode.png stbt-debug/00002/match1-confirm-absdiff_threshold.png stbt-debug/00002/match1-confirm-source_roi_gray_normalized.png stbt-debug/00002/match1-confirm-source_roi_gray.png stbt-debug/00002/match1-confirm-source_roi.png stbt-debug/00002/match1-confirm-template_gray_normalized.png stbt-debug/00002/match1-confirm-template_gray.png stbt-debug/00002/match1-heatmap.png stbt-debug/00002/match1-source_with_match.png stbt-debug/00002/match2-confirm-absdiff.png stbt-debug/00002/match2-confirm-absdiff_threshold_erode.png stbt-debug/00002/match2-confirm-absdiff_threshold.png stbt-debug/00002/match2-confirm-source_roi_gray_normalized.png stbt-debug/00002/match2-confirm-source_roi_gray.png stbt-debug/00002/match2-confirm-source_roi.png stbt-debug/00002/match2-confirm-template_gray_normalized.png stbt-debug/00002/match2-confirm-template_gray.png stbt-debug/00002/match2-heatmap.png stbt-debug/00002/match2-source_with_match.png stbt-debug/00002/match3-confirm-absdiff.png stbt-debug/00002/match3-confirm-absdiff_threshold_erode.png stbt-debug/00002/match3-confirm-absdiff_threshold.png stbt-debug/00002/match3-confirm-source_roi_gray_normalized.png stbt-debug/00002/match3-confirm-source_roi_gray.png stbt-debug/00002/match3-confirm-source_roi.png stbt-debug/00002/match3-confirm-template_gray_normalized.png stbt-debug/00002/match3-confirm-template_gray.png stbt-debug/00002/match3-heatmap.png stbt-debug/00002/match3-source_with_match.png stbt-debug/00002/match4-confirm-absdiff.png stbt-debug/00002/match4-confirm-absdiff_threshold_erode.png stbt-debug/00002/match4-confirm-absdiff_threshold.png stbt-debug/00002/match4-confirm-source_roi_gray_normalized.png stbt-debug/00002/match4-confirm-source_roi_gray.png stbt-debug/00002/match4-confirm-source_roi.png stbt-debug/00002/match4-confirm-template_gray_normalized.png stbt-debug/00002/match4-confirm-template_gray.png stbt-debug/00002/match4-heatmap.png stbt-debug/00002/match4-source_with_match.png stbt-debug/00002/match5-confirm-absdiff.png stbt-debug/00002/match5-confirm-absdiff_threshold_erode.png stbt-debug/00002/match5-confirm-absdiff_threshold.png stbt-debug/00002/match5-confirm-source_roi_gray_normalized.png stbt-debug/00002/match5-confirm-source_roi_gray.png stbt-debug/00002/match5-confirm-source_roi.png stbt-debug/00002/match5-confirm-template_gray_normalized.png stbt-debug/00002/match5-confirm-template_gray.png stbt-debug/00002/match5-heatmap.png stbt-debug/00002/match5-source_with_match.png stbt-debug/00002/match6-heatmap.png stbt-debug/00002/match6-source_with_match.png stbt-debug/00002/source.png stbt-debug/00002/source_with_matches.png stbt-debug/00002/template.png stbt-debug/00003 stbt-debug/00003/index.html stbt-debug/00003/level0-source_matchtemplate.png stbt-debug/00003/level0-source_matchtemplate_threshold.png stbt-debug/00003/level0-source.png stbt-debug/00003/level0-source_with_match.png stbt-debug/00003/level0-source_with_rois.png stbt-debug/00003/level0-template.png stbt-debug/00003/level1-source_matchtemplate.png stbt-debug/00003/level1-source_matchtemplate_threshold.png stbt-debug/00003/level1-source.png stbt-debug/00003/level1-source_with_match.png stbt-debug/00003/level1-source_with_rois.png stbt-debug/00003/level1-template.png stbt-debug/00003/level2-source_matchtemplate.png stbt-debug/00003/level2-source_matchtemplate_threshold.png stbt-debug/00003/level2-source.png stbt-debug/00003/level2-source_with_match.png stbt-debug/00003/level2-source_with_rois.png stbt-debug/00003/level2-template.png stbt-debug/00003/match0-confirm-absdiff.png stbt-debug/00003/match0-confirm-absdiff_threshold_erode.png stbt-debug/00003/match0-confirm-absdiff_threshold.png stbt-debug/00003/match0-confirm-source_roi_gray_normalized.png stbt-debug/00003/match0-confirm-source_roi_gray.png stbt-debug/00003/match0-confirm-source_roi.png stbt-debug/00003/match0-confirm-template_gray_normalized.png stbt-debug/00003/match0-confirm-template_gray.png stbt-debug/00003/match0-heatmap.png stbt-debug/00003/match0-source_with_match.png stbt-debug/00003/match1-confirm-absdiff.png stbt-debug/00003/match1-confirm-absdiff_threshold_erode.png stbt-debug/00003/match1-confirm-absdiff_threshold.png stbt-debug/00003/match1-confirm-source_roi_gray_normalized.png stbt-debug/00003/match1-confirm-source_roi_gray.png stbt-debug/00003/match1-confirm-source_roi.png stbt-debug/00003/match1-confirm-template_gray_normalized.png stbt-debug/00003/match1-confirm-template_gray.png stbt-debug/00003/match1-heatmap.png stbt-debug/00003/match1-source_with_match.png stbt-debug/00003/match2-confirm-absdiff.png stbt-debug/00003/match2-confirm-absdiff_threshold_erode.png stbt-debug/00003/match2-confirm-absdiff_threshold.png stbt-debug/00003/match2-confirm-source_roi_gray_normalized.png stbt-debug/00003/match2-confirm-source_roi_gray.png stbt-debug/00003/match2-confirm-source_roi.png stbt-debug/00003/match2-confirm-template_gray_normalized.png stbt-debug/00003/match2-confirm-template_gray.png stbt-debug/00003/match2-heatmap.png stbt-debug/00003/match2-source_with_match.png stbt-debug/00003/match3-confirm-absdiff.png stbt-debug/00003/match3-confirm-absdiff_threshold_erode.png stbt-debug/00003/match3-confirm-absdiff_threshold.png stbt-debug/00003/match3-confirm-source_roi_gray_normalized.png stbt-debug/00003/match3-confirm-source_roi_gray.png stbt-debug/00003/match3-confirm-source_roi.png stbt-debug/00003/match3-confirm-template_gray_normalized.png stbt-debug/00003/match3-confirm-template_gray.png stbt-debug/00003/match3-heatmap.png stbt-debug/00003/match3-source_with_match.png stbt-debug/00003/match4-confirm-absdiff.png stbt-debug/00003/match4-confirm-absdiff_threshold_erode.png stbt-debug/00003/match4-confirm-absdiff_threshold.png stbt-debug/00003/match4-confirm-source_roi_gray_normalized.png stbt-debug/00003/match4-confirm-source_roi_gray.png stbt-debug/00003/match4-confirm-source_roi.png stbt-debug/00003/match4-confirm-template_gray_normalized.png stbt-debug/00003/match4-confirm-template_gray.png stbt-debug/00003/match4-heatmap.png stbt-debug/00003/match4-source_with_match.png stbt-debug/00003/match5-confirm-absdiff.png stbt-debug/00003/match5-confirm-absdiff_threshold_erode.png stbt-debug/00003/match5-confirm-absdiff_threshold.png stbt-debug/00003/match5-confirm-source_roi_gray_normalized.png stbt-debug/00003/match5-confirm-source_roi_gray.png stbt-debug/00003/match5-confirm-source_roi.png stbt-debug/00003/match5-confirm-template_gray_normalized.png stbt-debug/00003/match5-confirm-template_gray.png stbt-debug/00003/match5-heatmap.png stbt-debug/00003/match5-source_with_match.png stbt-debug/00003/match6-confirm-absdiff.png stbt-debug/00003/match6-confirm-absdiff_threshold_erode.png stbt-debug/00003/match6-confirm-absdiff_threshold.png stbt-debug/00003/match6-confirm-source_roi_gray_normalized.png stbt-debug/00003/match6-confirm-source_roi_gray.png stbt-debug/00003/match6-confirm-source_roi.png stbt-debug/00003/match6-confirm-template_gray_normalized.png stbt-debug/00003/match6-confirm-template_gray.png stbt-debug/00003/match6-heatmap.png stbt-debug/00003/match6-source_with_match.png stbt-debug/00003/source.png stbt-debug/00003/source_with_matches.png stbt-debug/00003/template.png stbt-debug/00004 stbt-debug/00004/index.html stbt-debug/00004/level0-source_matchtemplate.png stbt-debug/00004/level0-source_matchtemplate_threshold.png stbt-debug/00004/level0-source.png stbt-debug/00004/level0-source_with_match.png stbt-debug/00004/level0-source_with_rois.png stbt-debug/00004/level0-template.png stbt-debug/00004/level1-source_matchtemplate.png stbt-debug/00004/level1-source_matchtemplate_threshold.png stbt-debug/00004/level1-source.png stbt-debug/00004/level1-source_with_match.png stbt-debug/00004/level1-source_with_rois.png stbt-debug/00004/level1-template.png stbt-debug/00004/level2-source_matchtemplate.png stbt-debug/00004/level2-source_matchtemplate_threshold.png stbt-debug/00004/level2-source.png stbt-debug/00004/level2-source_with_match.png stbt-debug/00004/level2-source_with_rois.png stbt-debug/00004/level2-template.png stbt-debug/00004/match0-confirm-absdiff.png stbt-debug/00004/match0-confirm-absdiff_threshold_erode.png stbt-debug/00004/match0-confirm-absdiff_threshold.png stbt-debug/00004/match0-confirm-source_roi_gray.png stbt-debug/00004/match0-confirm-source_roi.png stbt-debug/00004/match0-confirm-template_gray.png stbt-debug/00004/match0-heatmap.png stbt-debug/00004/match0-source_with_match.png stbt-debug/00004/match1-confirm-absdiff.png stbt-debug/00004/match1-confirm-absdiff_threshold_erode.png stbt-debug/00004/match1-confirm-absdiff_threshold.png stbt-debug/00004/match1-confirm-source_roi_gray.png stbt-debug/00004/match1-confirm-source_roi.png stbt-debug/00004/match1-confirm-template_gray.png stbt-debug/00004/match1-heatmap.png stbt-debug/00004/match1-source_with_match.png stbt-debug/00004/match2-confirm-absdiff.png stbt-debug/00004/match2-confirm-absdiff_threshold_erode.png stbt-debug/00004/match2-confirm-absdiff_threshold.png stbt-debug/00004/match2-confirm-source_roi_gray.png stbt-debug/00004/match2-confirm-source_roi.png stbt-debug/00004/match2-confirm-template_gray.png stbt-debug/00004/match2-heatmap.png stbt-debug/00004/match2-source_with_match.png stbt-debug/00004/match3-confirm-absdiff.png stbt-debug/00004/match3-confirm-absdiff_threshold_erode.png stbt-debug/00004/match3-confirm-absdiff_threshold.png stbt-debug/00004/match3-confirm-source_roi_gray.png stbt-debug/00004/match3-confirm-source_roi.png stbt-debug/00004/match3-confirm-template_gray.png stbt-debug/00004/match3-heatmap.png stbt-debug/00004/match3-source_with_match.png stbt-debug/00004/match4-confirm-absdiff.png stbt-debug/00004/match4-confirm-absdiff_threshold_erode.png stbt-debug/00004/match4-confirm-absdiff_threshold.png stbt-debug/00004/match4-confirm-source_roi_gray.png stbt-debug/00004/match4-confirm-source_roi.png stbt-debug/00004/match4-confirm-template_gray.png stbt-debug/00004/match4-heatmap.png stbt-debug/00004/match4-source_with_match.png stbt-debug/00004/match5-confirm-absdiff.png stbt-debug/00004/match5-confirm-absdiff_threshold_erode.png stbt-debug/00004/match5-confirm-absdiff_threshold.png stbt-debug/00004/match5-confirm-source_roi_gray.png stbt-debug/00004/match5-confirm-source_roi.png stbt-debug/00004/match5-confirm-template_gray.png stbt-debug/00004/match5-heatmap.png stbt-debug/00004/match5-source_with_match.png stbt-debug/00004/match6-confirm-absdiff.png stbt-debug/00004/match6-confirm-absdiff_threshold_erode.png stbt-debug/00004/match6-confirm-absdiff_threshold.png stbt-debug/00004/match6-confirm-source_roi_gray.png stbt-debug/00004/match6-confirm-source_roi.png stbt-debug/00004/match6-confirm-template_gray.png stbt-debug/00004/match6-heatmap.png stbt-debug/00004/match6-source_with_match.png stbt-debug/00004/source.png stbt-debug/00004/source_with_matches.png stbt-debug/00004/template.png """) assert_expected("stbt-debug-expected-output/match")
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 """)
def test_motion_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 def fake_frames(): for i, f in enumerate(["box-00001.png", "box-00002.png", "box-00003.png"]): yield stbt.Frame(stbt.load_image(f), time=i) with scoped_curdir(), scoped_debug_level(2): for _ in stbt.detect_motion(frames=fake_frames()): pass for _ in stbt.detect_motion(frames=fake_frames(), mask="box-00000.png"): pass for _ in stbt.detect_motion(frames=fake_frames(), region=stbt.Region(0, 0, 320, 400)): pass files = subprocess.check_output("find stbt-debug | sort", shell=True) assert files == dedent("""\ stbt-debug stbt-debug/00001 stbt-debug/00001/absdiff.png stbt-debug/00001/absdiff_threshold_erode.png stbt-debug/00001/absdiff_threshold.png stbt-debug/00001/gray.png stbt-debug/00001/index.html stbt-debug/00001/previous_frame_gray.png stbt-debug/00001/source.png stbt-debug/00002 stbt-debug/00002/absdiff.png stbt-debug/00002/absdiff_threshold_erode.png stbt-debug/00002/absdiff_threshold.png stbt-debug/00002/gray.png stbt-debug/00002/index.html stbt-debug/00002/previous_frame_gray.png stbt-debug/00002/source.png stbt-debug/00003 stbt-debug/00003/absdiff_masked.png stbt-debug/00003/absdiff.png stbt-debug/00003/absdiff_threshold_erode.png stbt-debug/00003/absdiff_threshold.png stbt-debug/00003/gray.png stbt-debug/00003/index.html stbt-debug/00003/mask.png stbt-debug/00003/previous_frame_gray.png stbt-debug/00003/source.png stbt-debug/00004 stbt-debug/00004/absdiff_masked.png stbt-debug/00004/absdiff.png stbt-debug/00004/absdiff_threshold_erode.png stbt-debug/00004/absdiff_threshold.png stbt-debug/00004/gray.png stbt-debug/00004/index.html stbt-debug/00004/mask.png stbt-debug/00004/previous_frame_gray.png stbt-debug/00004/source.png stbt-debug/00005 stbt-debug/00005/absdiff.png stbt-debug/00005/absdiff_threshold_erode.png stbt-debug/00005/absdiff_threshold.png stbt-debug/00005/gray.png stbt-debug/00005/index.html stbt-debug/00005/previous_frame_gray.png stbt-debug/00005/source.png stbt-debug/00006 stbt-debug/00006/absdiff.png stbt-debug/00006/absdiff_threshold_erode.png stbt-debug/00006/absdiff_threshold.png stbt-debug/00006/gray.png stbt-debug/00006/index.html stbt-debug/00006/previous_frame_gray.png stbt-debug/00006/source.png """) assert_expected("stbt-debug-expected-output/motion")
def test_match_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 with scoped_curdir(), scoped_debug_level(2): # First pass gives no matches: matches = list(stbt.match_all( "videotestsrc-redblue-flipped.png", frame=stbt.load_image("videotestsrc-full-frame.png"))) print matches assert len(matches) == 0 # Multiple matches; first pass stops with a non-match: matches = list(stbt.match_all( "button.png", frame=stbt.load_image("buttons.png"), match_parameters=mp(match_threshold=0.995))) print matches assert len(matches) == 6 # Multiple matches; second pass stops with a non-match: matches = list(stbt.match_all( "button.png", frame=stbt.load_image("buttons.png"))) print matches assert len(matches) == 6 # With absdiff: matches = list(stbt.match_all( "button.png", frame=stbt.load_image("buttons.png"), match_parameters=mp(confirm_method="absdiff", confirm_threshold=0.84))) print matches assert len(matches) == 6 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/level2-source_matchtemplate.png stbt-debug/00001/level2-source.png stbt-debug/00001/level2-source_with_match.png stbt-debug/00001/level2-source_with_rois.png stbt-debug/00001/level2-template.png stbt-debug/00001/match0-heatmap.png stbt-debug/00001/match0-source_with_match.png stbt-debug/00001/source.png stbt-debug/00001/source_with_matches.png stbt-debug/00001/template.png stbt-debug/00002 stbt-debug/00002/index.html stbt-debug/00002/level0-source_matchtemplate.png stbt-debug/00002/level0-source_matchtemplate_threshold.png stbt-debug/00002/level0-source.png stbt-debug/00002/level0-source_with_match.png stbt-debug/00002/level0-source_with_rois.png stbt-debug/00002/level0-template.png stbt-debug/00002/level1-source_matchtemplate.png stbt-debug/00002/level1-source_matchtemplate_threshold.png stbt-debug/00002/level1-source.png stbt-debug/00002/level1-source_with_match.png stbt-debug/00002/level1-source_with_rois.png stbt-debug/00002/level1-template.png stbt-debug/00002/level2-source_matchtemplate.png stbt-debug/00002/level2-source_matchtemplate_threshold.png stbt-debug/00002/level2-source.png stbt-debug/00002/level2-source_with_match.png stbt-debug/00002/level2-source_with_rois.png stbt-debug/00002/level2-template.png stbt-debug/00002/match0-confirm-absdiff.png stbt-debug/00002/match0-confirm-absdiff_threshold_erode.png stbt-debug/00002/match0-confirm-absdiff_threshold.png stbt-debug/00002/match0-confirm-source_roi_gray_normalized.png stbt-debug/00002/match0-confirm-source_roi_gray.png stbt-debug/00002/match0-confirm-source_roi.png stbt-debug/00002/match0-confirm-template_gray_normalized.png stbt-debug/00002/match0-confirm-template_gray.png stbt-debug/00002/match0-heatmap.png stbt-debug/00002/match0-source_with_match.png stbt-debug/00002/match1-confirm-absdiff.png stbt-debug/00002/match1-confirm-absdiff_threshold_erode.png stbt-debug/00002/match1-confirm-absdiff_threshold.png stbt-debug/00002/match1-confirm-source_roi_gray_normalized.png stbt-debug/00002/match1-confirm-source_roi_gray.png stbt-debug/00002/match1-confirm-source_roi.png stbt-debug/00002/match1-confirm-template_gray_normalized.png stbt-debug/00002/match1-confirm-template_gray.png stbt-debug/00002/match1-heatmap.png stbt-debug/00002/match1-source_with_match.png stbt-debug/00002/match2-confirm-absdiff.png stbt-debug/00002/match2-confirm-absdiff_threshold_erode.png stbt-debug/00002/match2-confirm-absdiff_threshold.png stbt-debug/00002/match2-confirm-source_roi_gray_normalized.png stbt-debug/00002/match2-confirm-source_roi_gray.png stbt-debug/00002/match2-confirm-source_roi.png stbt-debug/00002/match2-confirm-template_gray_normalized.png stbt-debug/00002/match2-confirm-template_gray.png stbt-debug/00002/match2-heatmap.png stbt-debug/00002/match2-source_with_match.png stbt-debug/00002/match3-confirm-absdiff.png stbt-debug/00002/match3-confirm-absdiff_threshold_erode.png stbt-debug/00002/match3-confirm-absdiff_threshold.png stbt-debug/00002/match3-confirm-source_roi_gray_normalized.png stbt-debug/00002/match3-confirm-source_roi_gray.png stbt-debug/00002/match3-confirm-source_roi.png stbt-debug/00002/match3-confirm-template_gray_normalized.png stbt-debug/00002/match3-confirm-template_gray.png stbt-debug/00002/match3-heatmap.png stbt-debug/00002/match3-source_with_match.png stbt-debug/00002/match4-confirm-absdiff.png stbt-debug/00002/match4-confirm-absdiff_threshold_erode.png stbt-debug/00002/match4-confirm-absdiff_threshold.png stbt-debug/00002/match4-confirm-source_roi_gray_normalized.png stbt-debug/00002/match4-confirm-source_roi_gray.png stbt-debug/00002/match4-confirm-source_roi.png stbt-debug/00002/match4-confirm-template_gray_normalized.png stbt-debug/00002/match4-confirm-template_gray.png stbt-debug/00002/match4-heatmap.png stbt-debug/00002/match4-source_with_match.png stbt-debug/00002/match5-confirm-absdiff.png stbt-debug/00002/match5-confirm-absdiff_threshold_erode.png stbt-debug/00002/match5-confirm-absdiff_threshold.png stbt-debug/00002/match5-confirm-source_roi_gray_normalized.png stbt-debug/00002/match5-confirm-source_roi_gray.png stbt-debug/00002/match5-confirm-source_roi.png stbt-debug/00002/match5-confirm-template_gray_normalized.png stbt-debug/00002/match5-confirm-template_gray.png stbt-debug/00002/match5-heatmap.png stbt-debug/00002/match5-source_with_match.png stbt-debug/00002/match6-heatmap.png stbt-debug/00002/match6-source_with_match.png stbt-debug/00002/source.png stbt-debug/00002/source_with_matches.png stbt-debug/00002/template.png stbt-debug/00003 stbt-debug/00003/index.html stbt-debug/00003/level0-source_matchtemplate.png stbt-debug/00003/level0-source_matchtemplate_threshold.png stbt-debug/00003/level0-source.png stbt-debug/00003/level0-source_with_match.png stbt-debug/00003/level0-source_with_rois.png stbt-debug/00003/level0-template.png stbt-debug/00003/level1-source_matchtemplate.png stbt-debug/00003/level1-source_matchtemplate_threshold.png stbt-debug/00003/level1-source.png stbt-debug/00003/level1-source_with_match.png stbt-debug/00003/level1-source_with_rois.png stbt-debug/00003/level1-template.png stbt-debug/00003/level2-source_matchtemplate.png stbt-debug/00003/level2-source_matchtemplate_threshold.png stbt-debug/00003/level2-source.png stbt-debug/00003/level2-source_with_match.png stbt-debug/00003/level2-source_with_rois.png stbt-debug/00003/level2-template.png stbt-debug/00003/match0-confirm-absdiff.png stbt-debug/00003/match0-confirm-absdiff_threshold_erode.png stbt-debug/00003/match0-confirm-absdiff_threshold.png stbt-debug/00003/match0-confirm-source_roi_gray_normalized.png stbt-debug/00003/match0-confirm-source_roi_gray.png stbt-debug/00003/match0-confirm-source_roi.png stbt-debug/00003/match0-confirm-template_gray_normalized.png stbt-debug/00003/match0-confirm-template_gray.png stbt-debug/00003/match0-heatmap.png stbt-debug/00003/match0-source_with_match.png stbt-debug/00003/match1-confirm-absdiff.png stbt-debug/00003/match1-confirm-absdiff_threshold_erode.png stbt-debug/00003/match1-confirm-absdiff_threshold.png stbt-debug/00003/match1-confirm-source_roi_gray_normalized.png stbt-debug/00003/match1-confirm-source_roi_gray.png stbt-debug/00003/match1-confirm-source_roi.png stbt-debug/00003/match1-confirm-template_gray_normalized.png stbt-debug/00003/match1-confirm-template_gray.png stbt-debug/00003/match1-heatmap.png stbt-debug/00003/match1-source_with_match.png stbt-debug/00003/match2-confirm-absdiff.png stbt-debug/00003/match2-confirm-absdiff_threshold_erode.png stbt-debug/00003/match2-confirm-absdiff_threshold.png stbt-debug/00003/match2-confirm-source_roi_gray_normalized.png stbt-debug/00003/match2-confirm-source_roi_gray.png stbt-debug/00003/match2-confirm-source_roi.png stbt-debug/00003/match2-confirm-template_gray_normalized.png stbt-debug/00003/match2-confirm-template_gray.png stbt-debug/00003/match2-heatmap.png stbt-debug/00003/match2-source_with_match.png stbt-debug/00003/match3-confirm-absdiff.png stbt-debug/00003/match3-confirm-absdiff_threshold_erode.png stbt-debug/00003/match3-confirm-absdiff_threshold.png stbt-debug/00003/match3-confirm-source_roi_gray_normalized.png stbt-debug/00003/match3-confirm-source_roi_gray.png stbt-debug/00003/match3-confirm-source_roi.png stbt-debug/00003/match3-confirm-template_gray_normalized.png stbt-debug/00003/match3-confirm-template_gray.png stbt-debug/00003/match3-heatmap.png stbt-debug/00003/match3-source_with_match.png stbt-debug/00003/match4-confirm-absdiff.png stbt-debug/00003/match4-confirm-absdiff_threshold_erode.png stbt-debug/00003/match4-confirm-absdiff_threshold.png stbt-debug/00003/match4-confirm-source_roi_gray_normalized.png stbt-debug/00003/match4-confirm-source_roi_gray.png stbt-debug/00003/match4-confirm-source_roi.png stbt-debug/00003/match4-confirm-template_gray_normalized.png stbt-debug/00003/match4-confirm-template_gray.png stbt-debug/00003/match4-heatmap.png stbt-debug/00003/match4-source_with_match.png stbt-debug/00003/match5-confirm-absdiff.png stbt-debug/00003/match5-confirm-absdiff_threshold_erode.png stbt-debug/00003/match5-confirm-absdiff_threshold.png stbt-debug/00003/match5-confirm-source_roi_gray_normalized.png stbt-debug/00003/match5-confirm-source_roi_gray.png stbt-debug/00003/match5-confirm-source_roi.png stbt-debug/00003/match5-confirm-template_gray_normalized.png stbt-debug/00003/match5-confirm-template_gray.png stbt-debug/00003/match5-heatmap.png stbt-debug/00003/match5-source_with_match.png stbt-debug/00003/match6-confirm-absdiff.png stbt-debug/00003/match6-confirm-absdiff_threshold_erode.png stbt-debug/00003/match6-confirm-absdiff_threshold.png stbt-debug/00003/match6-confirm-source_roi_gray_normalized.png stbt-debug/00003/match6-confirm-source_roi_gray.png stbt-debug/00003/match6-confirm-source_roi.png stbt-debug/00003/match6-confirm-template_gray_normalized.png stbt-debug/00003/match6-confirm-template_gray.png stbt-debug/00003/match6-heatmap.png stbt-debug/00003/match6-source_with_match.png stbt-debug/00003/source.png stbt-debug/00003/source_with_matches.png stbt-debug/00003/template.png stbt-debug/00004 stbt-debug/00004/index.html stbt-debug/00004/level0-source_matchtemplate.png stbt-debug/00004/level0-source_matchtemplate_threshold.png stbt-debug/00004/level0-source.png stbt-debug/00004/level0-source_with_match.png stbt-debug/00004/level0-source_with_rois.png stbt-debug/00004/level0-template.png stbt-debug/00004/level1-source_matchtemplate.png stbt-debug/00004/level1-source_matchtemplate_threshold.png stbt-debug/00004/level1-source.png stbt-debug/00004/level1-source_with_match.png stbt-debug/00004/level1-source_with_rois.png stbt-debug/00004/level1-template.png stbt-debug/00004/level2-source_matchtemplate.png stbt-debug/00004/level2-source_matchtemplate_threshold.png stbt-debug/00004/level2-source.png stbt-debug/00004/level2-source_with_match.png stbt-debug/00004/level2-source_with_rois.png stbt-debug/00004/level2-template.png stbt-debug/00004/match0-confirm-absdiff.png stbt-debug/00004/match0-confirm-absdiff_threshold_erode.png stbt-debug/00004/match0-confirm-absdiff_threshold.png stbt-debug/00004/match0-confirm-source_roi_gray.png stbt-debug/00004/match0-confirm-source_roi.png stbt-debug/00004/match0-confirm-template_gray.png stbt-debug/00004/match0-heatmap.png stbt-debug/00004/match0-source_with_match.png stbt-debug/00004/match1-confirm-absdiff.png stbt-debug/00004/match1-confirm-absdiff_threshold_erode.png stbt-debug/00004/match1-confirm-absdiff_threshold.png stbt-debug/00004/match1-confirm-source_roi_gray.png stbt-debug/00004/match1-confirm-source_roi.png stbt-debug/00004/match1-confirm-template_gray.png stbt-debug/00004/match1-heatmap.png stbt-debug/00004/match1-source_with_match.png stbt-debug/00004/match2-confirm-absdiff.png stbt-debug/00004/match2-confirm-absdiff_threshold_erode.png stbt-debug/00004/match2-confirm-absdiff_threshold.png stbt-debug/00004/match2-confirm-source_roi_gray.png stbt-debug/00004/match2-confirm-source_roi.png stbt-debug/00004/match2-confirm-template_gray.png stbt-debug/00004/match2-heatmap.png stbt-debug/00004/match2-source_with_match.png stbt-debug/00004/match3-confirm-absdiff.png stbt-debug/00004/match3-confirm-absdiff_threshold_erode.png stbt-debug/00004/match3-confirm-absdiff_threshold.png stbt-debug/00004/match3-confirm-source_roi_gray.png stbt-debug/00004/match3-confirm-source_roi.png stbt-debug/00004/match3-confirm-template_gray.png stbt-debug/00004/match3-heatmap.png stbt-debug/00004/match3-source_with_match.png stbt-debug/00004/match4-confirm-absdiff.png stbt-debug/00004/match4-confirm-absdiff_threshold_erode.png stbt-debug/00004/match4-confirm-absdiff_threshold.png stbt-debug/00004/match4-confirm-source_roi_gray.png stbt-debug/00004/match4-confirm-source_roi.png stbt-debug/00004/match4-confirm-template_gray.png stbt-debug/00004/match4-heatmap.png stbt-debug/00004/match4-source_with_match.png stbt-debug/00004/match5-confirm-absdiff.png stbt-debug/00004/match5-confirm-absdiff_threshold_erode.png stbt-debug/00004/match5-confirm-absdiff_threshold.png stbt-debug/00004/match5-confirm-source_roi_gray.png stbt-debug/00004/match5-confirm-source_roi.png stbt-debug/00004/match5-confirm-template_gray.png stbt-debug/00004/match5-heatmap.png stbt-debug/00004/match5-source_with_match.png stbt-debug/00004/match6-confirm-absdiff.png stbt-debug/00004/match6-confirm-absdiff_threshold_erode.png stbt-debug/00004/match6-confirm-absdiff_threshold.png stbt-debug/00004/match6-confirm-source_roi_gray.png stbt-debug/00004/match6-confirm-source_roi.png stbt-debug/00004/match6-confirm-template_gray.png stbt-debug/00004/match6-heatmap.png stbt-debug/00004/match6-source_with_match.png stbt-debug/00004/source.png stbt-debug/00004/source_with_matches.png stbt-debug/00004/template.png """) assert_expected("stbt-debug-expected-output/match")