Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中调用两个参数,但只调用一个参数_Python_Python 2.7_Gstreamer - Fatal编程技术网

在python中调用两个参数,但只调用一个参数

在python中调用两个参数,但只调用一个参数,python,python-2.7,gstreamer,Python,Python 2.7,Gstreamer,所以我想做的是,每当源板或接收器板上有一个事件时,探测回调函数就会在主线程中调用 对于函数“def probe_回调(MultiLink_pad,info):” 当我尝试运行此函数时,它给了我一个错误,说明: (TypeError:probe_callback()正好接受2个参数(给定1个)) 我遵循本网站的代码: 我试过了,但似乎对我不起作用。有人能帮我吗?不完全是python专家,但是在类之外定义回调函数怎么样(也许我完全错了)。。在C++中,当使用类时,总是将回调定义为类之外的C函数。事件

所以我想做的是,每当源板或接收器板上有一个事件时,探测回调函数就会在主线程中调用

对于函数“def probe_回调(MultiLink_pad,info):” 当我尝试运行此函数时,它给了我一个错误,说明:

(TypeError:probe_callback()正好接受2个参数(给定1个))

我遵循本网站的代码:


我试过了,但似乎对我不起作用。有人能帮我吗?

不完全是python专家,但是在类之外定义回调函数怎么样(也许我完全错了)。。在C++中,当使用类时,总是将回调定义为类之外的C函数。事件回调应该包含3个参数:pad、info、user\u data。。在用户数据中,pass通常是
这个
指针或元素指针,以后再使用它..check-搜索GST\u PAD\u PROBE\u TYPE\u EVENT\u下游你的缩进有点笨拙,
PROBE\u回调
应该是你的类的方法
TakePhoto
?不完全是python专家,但是在类之外定义回调函数怎么样(也许我完全错了)。。在C++中,当使用类时,总是将回调定义为类之外的C函数。事件回调应该包含3个参数:pad、info、user\u data。。在用户数据中,pass通常是
这个
指针或元素指针,以后再使用它..check-搜索GST\u PAD\u PROBE\u TYPE\u EVENT\u下游您的缩进有点笨拙,
PROBE\u回调
应该是类的一个方法
TakePhoto
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject #,Gtk
from gi.repository import Gst as gst


class TakePhoto:

  def __init__(self):
    GObject.threads_init()
    gst.init(None)
    self.pipeline = gst.Pipeline()
    self.video_source = gst.ElementFactory.make('v4l2src', 'video_source')
    self.video_source.set_property("num-buffers",1)
    self.vconvert = gst.ElementFactory.make('videoconvert', 'vconvert')
    self.png = gst.ElementFactory.make('pngenc', 'png')
    self.multisink = gst.ElementFactory.make('multifilesink', 'multisink')
    self.multisink_pad = self.multisink.get_static_pad("sink")
    self.multisink_pad.add_probe(gst.PadProbeType.EVENT_UPSTREAM,self.probe_callback)

    self.caps = gst.caps_from_string("video/x-raw,format=RGB,width=800,height=600,framerate=5/1")
    self.png.set_property('snapshot',True)
    self.multisink.set_property('location','/home/pi/frame.png')
    self.filter = gst.ElementFactory.make("capsfilter", "filter")
    self.filter.set_property("caps", self.caps)


    self.pipeline.add(self.video_source)
    self.pipeline.add(self.vconvert)
    self.pipeline.add(self.filter)
    self.pipeline.add(self.png)
    self.pipeline.add(self.multisink)

    self.video_source.link(self.filter)
    self.filter.link(self.vconvert)
    self.vconvert.link(self.png)
    self.png.link(self.multisink)

def probe_callback(multisink_pad,info):
    info_event = info.get_event()
    info_structure = info_event.get_structure()
    do_something_with_this_info
    return Gst.PadProbeReturn.PASS


def take_photo(self): #this is reusable
    bus = self.pipeline.get_bus()
    self.pipeline.set_state(gst.State.PLAYING)
    print "Capture started"
    msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE,gst.MessageType.ERROR | gst.MessageType.EOS)
    print msg

    self.pipeline.set_state(gst.State.NULL)