Esempio n. 1
0
    def process_frame(self, frame, frame_number, frame_count, frame_time, current_time, state):
        time.sleep(0.1)
        if self._i > self._n:
            raise PluginFinished
        self._i += 1
        self.logger.debug("%s got %r as state" % (self._k, state.keys()))
        return {self._k: self._vfunc()}

    def stop(self):
        self.logger.debug("finished")

if __name__ == "__main__":
    import logging
    logging.basicConfig(level=logging.DEBUG)

    fview = Microfview.new_from_commandline(cap_fallback=get_capture_object("synth:class=dot:fps=2:nframes=10"))

    chain = PluginChain(
                MyPlugin('even',
                         lambda: random.choice((2,4,6,8)),
                         5),
                MyPlugin('odd',
                         lambda: random.choice((1,3,5,7)),
                         10)
    )
    fview.attach_plugin(chain)
    fview.attach_plugin(TestNonBlocking())
    fview.main()


        self.uses_color = True
        self.human_name = "%s(channel=%s)" % (self.__class__.__name__, self._channel)

    def process_frame(self, frame, frame_number, frame_count, frame_time, current_time, state):
        return cv2.inRange(frame[:,:,self._channel], self._vmin, self._vmax)

class Slow(BlockingPlugin):
    def process_frame(self, *args):
        time.sleep(0.05)

if __name__ == "__main__":
    import logging
    logging.basicConfig(level=logging.DEBUG)

    fview = Microfview.new_from_commandline(cap_fallback=get_capture_object("synth:class=dot:bg=graffiti.png"))

    blue = PluginChain(ChannelSeparator(0),
                       DisplayPlugin('blue', original_frame=False),
                       Slow())
    fview.attach_parallel_plugin(blue)
    green = PluginChain(ChannelSeparator(1),
                        DisplayPlugin('green', original_frame=False))
    fview.attach_parallel_plugin(green)
    red = PluginChain(ChannelSeparator(2),
                      DisplayPlugin('red', original_frame=False),
                      Slow())
    fview.attach_parallel_plugin(red)

    fview.main()