当前位置: 首页>>代码示例>>Python>>正文


Python Queue.push方法代码示例

本文整理汇总了Python中multiprocessing.Queue.push方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.push方法的具体用法?Python Queue.push怎么用?Python Queue.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.Queue的用法示例。


在下文中一共展示了Queue.push方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Controller

# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import push [as 别名]
class Controller(object):
    def __init__(self):
        motor = get_motor(motor_debug)
        trigger = get_trigger(debug)
        self.motor = motor
        self.video_tracker = None
        print "CONNECTING Motor"
        motor.connect()
        print "CONNECTING Trigger"
        self.trigger = trigger.Trigger()
        print "CONNECTING Joystick"
        self.init_joystick()
        self.manual = False
        self.x = None
        self.y = None
        self.fire_duration = 200
        self.video_tracker = None

    def _unused_init_detect_process(self):
        self.video_in = Queue()
        self.video_out = Queue()
        self.detect_process = DetectProcess(inq=self.video_in, outq=self.video_out)
        self.detect_process.start()

    def on_frame(self, b):
        ret = inp = numpy.fromstring(b.data, dtype=numpy.uint8).reshape(480, 720, 3)
        if not self.video_tracker:
            self.video_tracker = VideoTracker(initial_frame=inp, on_cx_cy=self.on_cx_cy)
        else:
            ret = self.video_tracker.on_frame(inp)
        return gst.Buffer(ret)

    def on_frame_process(self, b):
        ret = inp = numpy.fromstring(b.data, dtype=numpy.uint8).reshape(480, 720, 3)
        print "pushing"
        self.video_in.push("test")
        print "popping"
        ret_unused = self.video_out.pop()
        assert ret_unused == "testout"
        print "popped"
        return gst.Buffer(ret)

    def init_joystick(self):
        self.j = joystick.Joystick()
        self.j.connect("axis", self.on_axis)
        self.j.connect("button", self.on_button)

    def on_axis(self, signal, code, value):
        print "on_axis %s %s" % (code, value)
        # print "on_axis %d, %d" % (code, value)
        if code not in [0, 1, 2]:
            return
        if code == 0:
            self.x = value
            if self.manual:
                self.motor.theta.set(state.x - 127)
        elif code == 1:
            self.y = value
            if self.manual:
                self.motor.pitch.set(state.y - 127)
        else:
            fire_duration = 100 + (float(value) / 255.0) * 900
            print "joy: %d => fire dur %d" % (value, fire_duration)
            self.fire_duration = int(fire_duration)

    def on_button(self, signal, code, value):
        print "on_button: %d, %d" % (code, value)
        if value != 1 or code != 0:
            return
        print " **** FIRE ****"
        self.trigger.fire(self.fire_duration)

    def on_cx_cy(self, cx, cy):
        # print "controller: got (%d, %d)" % (cx, cy)
        cx -= 720 / 2
        cy -= 480 / 2
        for axis, val in [(self.motor.theta, cx), (self.motor.pitch, cy)]:
            if abs(val) > 10:
                print "action %r" % axis
                axis.set(200 if cx > 0 else -200)
开发者ID:alon,项目名称:geekcon2012,代码行数:82,代码来源:main.py


注:本文中的multiprocessing.Queue.push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。