• 大小: 4KB
    文件类型: .py
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: Python
  • 标签: gstreamer  camera  

资源简介

展示了在python语言中用gstreamer打开摄像头示例,示例用一个单独线程操作

资源截图

代码片段和文件信息

#!/usr/bin/python
# -*- coding: utf-8 -*-
import ossyscv2gi
import threading time
gi.require_version(‘Gst‘ ‘1.0‘)
from gi.repository import Gobject Gst

row = 100

class cameraWork(threading.Thread):
    def __init__(self num callback1 callback2 exit_sema init_sema):
        super(cameraWork self).__init__()
        print “camera thread init“
        self.cb1 = callback1
        self.cb2 = callback2
        self.data = False
        self.exit_flag = 0
        self.error_flag = 0
        self.exit_sema = exit_sema
        self.init_sema = init_sema
        self.num = num 
        
        Gst.init(None)
        self.player = Gst.Pipeline(name=“cam“)
        self.source = Gst.ElementFactory.make(“v4l2src“ “src“)
        self.scaps = Gst.caps_from_string(“video/x-raw width=1280height=720format=I420“)
        self.capssrc = Gst.ElementFactory.make(“capsfilter“ None)
        self.capssrc.set_property(“caps“ self.scaps)
        self.ccaps = Gst.caps_from_string(“video/x-raw width=1280height=720format=RGB16“)
        self.capscov = Gst.ElementFactory.make(“capsfilter“ None)
        self.capscov.set_property(“caps“ self.ccaps)
        self.cov = Gst.ElementFactory.make(“videoconvert“ ‘cov‘)
        self.sink = Gst.ElementFactory.make(“appsink“ “out“)
        self.source.set_property(“device“ “/dev/video“+str(num))

    def run(self):
        print “camera thread run“

        pipeline_elements = [self.source self.capssrc self.cov self.capscov self.sink]
        for elem in pipeline_elements:
            self.player.add(elem)
        for i in range(len(pipeline_elements[:-1])):
            Gst.Element.link(pipeline_elements[i] pipeline_elements[i+1])

        #self.player.add(self.source)
        #self.player.add(self.capssrc)
        #self.player.add(self.cov)
        #self.player.add(self.capscov)
        #self.player.add(self.sink)

        #self.source.link(self.capssrc)
        #self.capssrc.link(self.cov)
        #self.cov.link(self.capsc

评论

共有 条评论