stbt-record: Fix pylint error

stbt-record:14: [W0611] Unused import gst
stbt control: Do not raise `curses.error` if the terminal is too small

`stbt control` uses `curses` module for terminal handling. `curses`
raises the unhelpful `curses.error` exception if the terminal is smaller
than what is required to print the keymap.

If the terminal is too small do not print the keymap and print an error
message instead, but do not quit the tool as the more experienced users
who remember key mappings might not need the printed keymap at all.
stbt-completion: Don't suggest short options

Offering suggestions for both the short ("-v") and long ("--verbose")
options clutters the output.
stbt.detect_motion: Fix invalid use of mask in OpenCV operation

The "mask" parameter to "bitwise_and" means that the operation only
changes those destination array pixels "p" for which "mask(p)" != 0.
Since we're not specifying "dst" (destination), "bitwise_and" allocates
a new output array, but doesn't initialize it properly, so anything in
the output image in the area corresponding to the 0 pixels in the mask
contain garbage, rather than 0. See
http://code.opencv.org/issues/1748#note-2

This fixes the behaviour described in
http://answers.opencv.org/question/15279

Presumably the reason I didn't see this behaviour in OpenCV 2.4.5 is
because of http://code.opencv.org/issues/1286
README: Don't mention GStreamer elements in "-vv" documentation

We removed the GStreamer elements in a35848f2. Note that since 4e7de9dc
we create a separate subdirectory for the debug images relating to
different input video frames.
Revert "Disable Travis CI (remove .travis.yml config file)"

This reverts commit 1ff14a15554867e6eaf6419a6aee2ced6fb807a6.

The original commit disabled Travis-CI because Travis-CI's version
of OpenCV (2.3) was causing a unit test to fail. Commit 4b301f9 allows
the test to pass on OpenCV 2.3, so we can enable Travis-CI again.
stbt.Display.frames: Always return at least 1 frame

"frames(timeout_secs=0)" would fail with a "Queue.Empty" exception if
called twice in quick succession.

The timeout to "Queue.get" is unrelated to the overall "timeout_secs" of
"frames" (and "detect_match", "detect_motion", etc). The latter are
based on the stream timestamp; the "Queue.get" timeout only has effect
when the GStreamer pipeline isn't delivering any video. There are 2
reasons why there isn't any video:

1. The HDPVR momentarily lost video input, so it switched off. See
   b6135eca. 10 seconds will be enough time to restart the pipeline
   once.

   (Note that we don't want to implement the pipeline restarting
   behaviour here inside "frames" because we want to restart the
   pipeline as soon as video loss is detected, not only when the user's
   script calls "frames". The current implementation listens to
   "underrun" signals from the GStreamer pipeline, in a separate
   thread).

2. The system-under-test isn't delivering video. This might be expected,
   for example if the test script has rebooted the system-under-test. In
   that case your test script would say something like:

       restart_system_under_test()
       wait_for_match('splash_screen.png', timeout_secs=30)

   We want to allow those 30 seconds for video to reappear. In this
   commit's implementation it's possible that we allow a much longer
   timeout:

   * The first 29 seconds of frames *do* have video, but
     "wait_for_match" doesn't find a match.
   * Then in the 30th second we lose video, and we allow an additional
     30s timeout to get the next frame.

   But I don't think that's a big problem. If a test permanently loses
   video it will take a bit longer to fail, that's all.

This commit also gives a "no video" timeout the same behaviour (as seen
by the caller) as a timeout based on the stream timestamps: The
generator returns. Callers like "wait_for_match" can then choose to
raise an Exception like "MatchTimeout".
stbt.Display.frames: Document format of yielded images
stbt.Display.frames: Disable timeout by default

Note that the public API to this function is via "detect_match",
"wait_for_match", "detect_motion", etc. Those functions all continue to
take a default "timeout_secs" of 10, which they pass on to "frames". So
existing users won't be affected. New users will be able to use frames
to get an unlimited supply of frames, if they so desire. (At least,
they *will* be able to once we make "frames" publicly accessible.)

Note however that the "no input video" timeout of 10 seconds will still
apply.

The unit test takes 12s to run, because the previous default timeout was
10s. Hopefully this won't increase the total runtime of the test suite
too much, at least if you install GNU parallel (see 42d1d8aa).
make check: Force GNU parallel's GNU mode

Fedora 18 sets the "--tollef" flag in /etc/parallel/config, which forces
GNU parallel to behave like the moreutils parallel. We explicitly want
GNU parallel, which behaves like xargs (it takes each command's
arguments on standard input).
Revert "README: Update required OpenCV version to 2.4"

This reverts commit 5455ac04d7824bb5a297ddd6aed0f3f8d55b6ae2.

It turns out that it wasn't exactly a bug in OpenCV < 2.4, but incorrect
use of the API on our part. See 4b301f92 for details.
Revert "rpm spec file: Require opencv >= 2.4"

This reverts commit c25d743cbb258ba26695f493a2c6f35181d45d9d.

It turns out that it wasn't exactly a bug in OpenCV < 2.4, but incorrect
use of the API on our part. See 4b301f92 for details.
stbt.py: store `MatchParameters.match_method` as a string

Currently the `MatchParameters` constructor maps the `match_method`
argument (str) to the corresponding OpenCV match method enum (int).
While the value is passed in as a string, it is stored as an integer.

This makes it difficult to reconstruct the string representation of the
`match_method`. In addition, if it is necessary to override the value in
an existing MatchParameters instance, the mapping would have to be
performed by the user manually:

    params = stbt.MatchParameters()
    ...
    params['match_method'] = cv2.TM_SQDIFF_NORMED

This change keeps the `MatchParameters.match_method` as a string, but
converts it to the OpenCV enum at the point at which it is used (the
`_match_template()` function). A new variable `match_method_cv` is
introduced in `_match_template()` to perform the mapping.
test_detect_motion_times_out_during_yield: Fix intermittent failure

This applies the same fix as 0d460f18 did to
test_detect_*match*_times_out_during_yield.
stbt.Display.frames: Raise `NoVideo` instead of returning `None`

...when there is no video available from the GStreamer source
pipeline (i.e. the video-capture hardware).

This allows callers to distinguish between "no video available" and
"we've received so many frames that the timeout_secs we specified has
been reached".

Functions like `detect_match` and `wait_for_match` will now raise
`NoVideo` instead of `MatchTimeout` when there is no video.

`NoVideo` is considered a test *failure* (not an *error*) because it
could mean that the system-under-test has crashed or otherwise stopped
delivering video.

Of the two video-capture hardware devices that I have experience with,
only the Hauppauge HDPVR will stop delivering frames when it has no
input video, and thus will trigger this timeout. The Blackmagic
Intensity Pro card simply continues to deliver black frames when it has
no video on its input (this will be detected by a `wait_for_match` in
the user's script that is looking for something other than all-black).
stbt.get_frame: Wait for the next available frame

If called before any frames are available (e.g. before the GStreamer
pipeline has fully initialised, or if the system-under-test isn't
delivering any video), `get_frame` will wait up to `timeout_secs`
seconds. Previously `get_frame` returned `None` if no video was
available.

One minor consequence of this is that the screenshot attached to the
`MatchTimeout` raised by `wait_for_match` is *guaranteed* to be a frame
*after* the last frame analysed by `wait_for_match`, instead of
only *sometimes* being a different frame. Maybe we can attach the actual
frame to each `MatchResult` object, but that's for a different commit.

Fixes #23, fixes #33.
stbt.{Match,Motion}Timeout.screenshot: Document format of image

Since ca4201df, this is an OpenCV image, not a GStreamer buffer.
test_that_frames_raises_NoVideo: Fix failure on travis-ci

The failure was:

> grep: input file `/tmp/stb-tester.TXa/log' is also the output
Printable error message for NoVideo exception raised by stbt.get_frame

Before this change, the "FAIL: ..." error message printed to stdout by
stbt-run was empty (it just said "FAIL: <test name>: ").
stbt.py: Add section markers for Emacs

These "Control-L" characters are "form feed", which are considered as
whitespace by editors and the python interpreter. Emacs uses these
characters to navigate between sections or "pages" -- see
http://www.gnu.org/software/emacs/manual/html_node/emacs/Pages.html