drothlis/stb-tester — pull request #114 by wmanley (2014-03-13 18:11:25+00:00)
Title: Allow passing a numpy array as a template to match functions

Allow passing a numpy array as a template to match functions

This allows templates to be generated on-the-fly without having to create intermediate image files. This will be used for Smart TV support some of our test patterns are generated from textual descriptions and we want to match sub-images within them. e.g. the "letters" test pattern looks like:

ABCDEFG
HIJKLMN
OPQRSTU

and we want to check the locations of each of the letters to confirm that they're in the right places.

Nonetheless it seems that this could be generally very useful.

Possible example uses:

* You are navigating a carousel of DVD box covers and want to check that it correctly wraps back to the beginning. The code could look like:

# Grab the currently shown DVD cover given that we know its
# location and size:
initial_dvd_cover = stbt.get_frame()[300:700,500:700]

stbt.press("KEY_RIGHT")
stbt.press_until_match("KEY_RIGHT", initial_dvd_cover)

* You have an image and you want to find out which way up it is being displayed:

def get_orientation():
arrow = cv2.imread("arrow.png")
if matches(arrow):
return 1
elif matches(cv2.flip(arrow)):
return -1
else:
raise RuntimeError("Can't find arrow")

Future work: This feature (and stb-tester in general) would really benefit with some tutorial style documentation to help introduce concepts and explain when the various features of stb-tester should be applied.

This feature is a dependency of #100 (Smart TV support) and has been split out of the list of commits on that pull request.