gpt4 book ai didi

python-3.x - 无法使用Gstreamer-Python设置两个摄像机的参数

转载 作者:行者123 更新时间:2023-12-02 16:18:50 26 4
gpt4 key购买 nike

我正在尝试使用Gstreamer(Python3)同时设置两个摄像机的摄像机参数(曝光和增益)。我使用相机序列ID创建了两个单独的管道,此后遵循了用于单个(唯一)相机管道的方法。但是,执行脚本后,仅会为其中一台摄像机设置参数。下面的代码中我应该修改什么? TIA。

#!/usr/bin/env python3


import time
import sys
import gi

gi.require_version("Tcam", "0.1")
gi.require_version("Gst", "1.0")

from gi.repository import Tcam, Gst


def main():

Gst.init(sys.argv) # init gstreamer

serial1='05020863'
serial2='05020864'

pipeline1 = Gst.parse_launch("tcambin name=source1"
" ! video/x-raw,format=BGRx,width=720,height=540,framerate=30/1"
" ! tee name=t"
" ! queue"
" ! videoconvert"
" ! ximagesink"
" t."
" ! queue"
" ! videoconvert"
" ! avimux"
" ! filesink name=fsink1")

pipeline2 = Gst.parse_launch("tcambin name=source2"
" ! video/x-raw,format=BGRx,width=720,height=540,framerate=30/1"
" ! tee name=t"
" ! queue"
" ! videoconvert"
" ! ximagesink"
" t."
" ! queue"
" ! videoconvert"
" ! avimux"
" ! filesink name=fsink2")

if serial1 is not None:
camera1 = pipeline1.get_by_name("source1")
camera1.set_property("serial", serial1)

if serial2 is not None:
camera2 = pipeline2.get_by_name("source2")
camera2.set_property("serial",serial2)

file_location1 = "/home/pandey/TIS/tiscamera/examples/python/tiscamera-save-stream-1.avi"
file_location2 = "/home/pandey/TIS/tiscamera/examples/python/tiscamera-save-stream-2.avi"

camera1 = Gst.ElementFactory.make("tcambin")
camera2 = Gst.ElementFactory.make("tcambin")

camera1.set_state(Gst.State.READY)
camera1.set_tcam_property("Exposure Auto", False)
camera1.set_tcam_property("Gain Auto", False)

camera2.set_state(Gst.State.READY)
camera2.set_tcam_property("Exposure Auto", False)
camera2.set_tcam_property("Gain Auto", False)

camera1.set_tcam_property("Exposure Time",10)
camera1.set_tcam_property("Gain",450)

camera2.set_tcam_property("Exposure Time",10)
camera2.set_tcam_property("Gain",450)


fsink1 = pipeline1.get_by_name("fsink1")

fsink1.set_property("location", file_location1)

fsink2 = pipeline2.get_by_name("fsink2")

fsink2.set_property("location", file_location2)


pipeline1.set_state(Gst.State.PLAYING)

pipeline2.set_state(Gst.State.PLAYING)




print("Press Ctrl-C to stop.")

try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
pipeline1.set_state(Gst.State.NULL)
pipeline2.set_state(Gst.State.NULL)


if __name__ == "__main__":
main()

最佳答案

您的问题在这里:

camera1 = Gst.ElementFactory.make("tcambin")
camera2 = Gst.ElementFactory.make("tcambin")
为什么要创建两个与管道完全分离的新元素并准备就绪?您应该只使用(就像您之前正确地做过的一样)
camera1 = pipeline1.get_by_name("source1")
camera2 = pipeline1.get_by_name("source2")
获得对管道中实际元素的引用。

关于python-3.x - 无法使用Gstreamer-Python设置两个摄像机的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62646026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com