Пример #1
0
    def frames(self):
        if self._frames is not None:
            # Ignore self.state, send the specified frames instead.
            t = time.time()
            for state in self._frames:
                array = F(state, t)
                yield stbt.Frame(array, time=t)
                t += 0.04  # 25fps

        else:
            while True:
                t = time.time()
                array = F(self.state, t)
                if self.state == "fade-to-black":
                    self.state = "black"
                elif self.state == "fade-to-white":
                    self.state = "white"
                yield stbt.Frame(array, time=t)
Пример #2
0
def test_motionresult_repr():
    assert repr(stbt.MotionResult(
        time=1466002032.335607, motion=True,
        region=stbt.Region(x=321, y=32, right=334, bottom=42),
        frame=stbt.Frame(numpy.zeros((720, 1280, 3)),
                         time=1466002032.335607))) \
        == ("MotionResult("
            "time=1466002032.336, motion=True, "
            "region=Region(x=321, y=32, right=334, bottom=42), "
            "frame=<stbt.Frame(time=1466002032.336, dimensions=1280x720x3)>)")
Пример #3
0
def test_that_slicing_a_Frame_is_still_a_Frame():
    f = stbt.Frame(numpy.zeros((720, 1280, 3), dtype=numpy.uint8), time=1234)

    f1 = f[10:20, 10:, 0]
    assert isinstance(f1, stbt.Frame)
    assert f1.time == 1234

    f2 = stbt.crop(f, stbt.Region(10, 10, 20, 20))
    assert isinstance(f2, stbt.Frame)
    assert f2.time == 1234

    f3 = f.copy()
    assert isinstance(f3, stbt.Frame)
    assert f3.time == 1234
    assert (f.__array_interface__["data"][0] !=
            f3.__array_interface__["data"][0])

    f4 = stbt.Frame(f)
    assert f4.time == 1234
Пример #4
0
def fake_frames():
    a = numpy.zeros((2, 2, 3), dtype=numpy.uint8)
    a.flags.writeable = False
    b = numpy.ones((2, 2, 3), dtype=numpy.uint8) * 255
    b.flags.writeable = False

    # Motion:                 v     v     v     v     v     v     v     v     v
    data = [
        a, a, a, a, a, a, b, b, a, a, b, b, a, a, b, b, a, a, b, b, a, a, b
    ]
    #       ^                 ^
    #       |                 L Motion starts here at timestamp 1466084606.
    #       L Video starts here at timestamp 1466084600

    start_time = time.time()
    for n, x in enumerate(data):
        t = start_time + n
        time.sleep(t - time.time())
        yield stbt.Frame(x, time=t)
Пример #5
0
def gradient_wipe(min_=100, max_=200, swipe_height=40):
    """Use write_video(gradient_wipe()) to see what this looks like."""
    frame = min_ * numpy.ones(
        (720 + swipe_height * 4, 1280, 3), dtype=numpy.uint8)
    diff = max_ - min_

    # detect_motion ignores differences of under 40, so what's the fastest we
    # can wipe while making sure the inter-frame differences are always under
    # 40?:
    speed = 40 * swipe_height / diff

    print("pixel difference: %f" % (diff / swipe_height))
    print("max_speed: %f" % speed)

    edge = numpy.ones((swipe_height * 3, 1280, 3), dtype=numpy.uint8) * min_
    for n in range(swipe_height * 3):
        edge[n, :, :] = clamp(max_ - (n - swipe_height) * diff / swipe_height,
                              min_, max_)

    for x in range(0, frame.shape[0] - swipe_height * 3, int(speed)):
        frame[x:x + swipe_height * 3, :, :] = edge
        yield stbt.Frame(frame[swipe_height * 2:swipe_height * 2 + 720],
                         time=x / 30.)
Пример #6
0
 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)
Пример #7
0
def wipe():
    frame = numpy.zeros((720, 1280, 3), dtype=numpy.uint8)
    for x in range(0, 720, 2):
        frame[x:x + 2, :, :] = 255
        yield stbt.Frame(frame, time=x / 30.)