【问题标题】:Using gstreamer with Python OpenCV to capture live stream?使用带有 Python OpenCV 的 gstreamer 来捕获实时流?
【发布时间】:2018-10-18 17:28:41
【问题描述】:

首先,我有 Python 3,其中包含 Gstreamer 库。

print(cv2.getBuildInformation())

它在 Gstreamer 旁边显示 YES。

这是在 RaspberryPi 3 中使用 gstreamer 的发射器代码:

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 代码来确定形状、识别物体等。

这是我的 Python 代码:

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();

但它总是显示空框。

当我在终端尝试这个命令时:

gst-launch-1.0 udpsrc port=10000 ! application/x-rtp,encoding-name=H264 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! videoconvert ! ximagesink

它工作得很好,所以问题出在我的 Python 端。

你有什么推荐的?

【问题讨论】:

  • 在你的python代码中,你写了ximagesin,也许这就是问题所在?

标签: python opencv gstreamer


【解决方案1】:
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)

使用这个管道,它会工作得很好。 将端口更改为您正在使用的端口。

【讨论】:

    【解决方案2】:

    当从命令行运行时,我使用不同的发送-接收脚本,这些脚本可以提供更好的视频延迟(同样在更高分辨率下),但我不知道如何在 Ubuntu 端将生成的流导入 OpenCV。

    (我的 OpenCV 也安装了 ffmpeg 和 gstreamer。)

    我的树莓派上的 GStreamer 发射器代码:

    gst-launch-1.0 -v v4l2src ! video/x-raw,width=320,height=240 ! videoconvert ! jpegenc ! rtpjpegpay ! udpsink host=192.168.1.101 port=5200 
    

    我在 Ubuntu 16.04 端的 Gstreamer Receiver 代码:

    gst-launch-1.0 -v udpsrc port=5200 ! application/x-rtp, encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! videoconvert ! autovideosink 
    

    我希望这将帮助您提高直播质量和延迟。 我希望有人可以给我采样 OpenCV 管道导入代码:)

    您好, 彼得·伦克

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 2020-07-03
      • 2016-11-01
      • 2019-02-13
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多