使用gstreamer与python opencv捕获实时流? [英] using gstreamer with python opencv to capture live stream?
本文介绍了使用gstreamer与python opencv捕获实时流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先,我拥有带有Gstreamer库的python 3.
First of all i have python 3 with the library Gstreamer in it.
print(cv2.getBuildInformation())
它显示Gstreamer,旁边是"YES".
it shows Gstreamer with YES next to it.
这是在rasperryPi 3中使用gstreamer的发送器代码.
Here is the transmitter code using gstreamer in rasperryPi 3:
gst-launch-1.0 v4l2src device="/dev/video0" ! video/x-raw,width=320,height=240 ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host='my ip address' port=10000
并且我将使用python代码确定形状,识别对象等.
and i will be using a python code to determine shapes , recognize objects .. etc
这是我的python代码:
here is my python code:
import numpy as np
import cv2
def receive():
cap = cv2.VideoCapture("udpsrc port=10000 ! application/x-rtp,encoding-name=H264 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! videoconvert ! ximagesin ", cv2.CAP_GSTREAMER)
while True:
ret,frame = cap.read()
if not ret:
print('empty frame')
continue
cv2.imshow('receive', frame)
if cv2.waitKey(1)&0xFF == ord('q'):
break
cap.release()
receive();
但它始终显示空白帧.
当我在终端上尝试此命令时:
when i tried this command on terminal:
gst-launch-1.0 udpsrc port=10000 ! application/x-rtp,encoding-name=H264 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! videoconvert ! ximagesink
它工作正常,所以问题出在我的python端.
it works just fine, so the problem is on my python end.
那你有什么建议?
推荐答案
cap = cv2.VideoCapture('udpsrc port=7000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
使用此管道,它将正常工作.将端口更改为您正在使用的端口.
use this pipeline, it will work just fine. change the port to the one you are using.
这篇关于使用gstreamer与python opencv捕获实时流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文