python - 将gstreamer管道更改为python中的opencv

标签 python opencv gstreamer ip-camera hikvision

我已经在opencv上成功安装并构建了gstreamer。当我打印(cv2.getBuildInformation())时说是。

Gstreamer version: 1.14.0
opencv version: 3.4.5.20

此刻,使用gstreamer管道撞到墙上已经有一段时间了。效果很好。
gst-launch-1.0 -v playbin uri=rtsp://admin:password@192.168.1.65:554/Streaming/Channels/400 uridecodebin0::source::latency=10

这是我为gstreamer管道编写的python脚本。
import cv2
import numpy as np

pipe = '"rtspsrc location=\"rtsp://admin:password@192.168.1.65:554/Streaming/Channels/400" latency=10 ! appsink'

cap = cv2.VideoCapture(pipe)

if not cap.isOpened():
    print('VideoCapture not opened')
    exit(0)

while True:
    ret, frame = cap.read()

    if not ret:
        print('empty frame')
        break

    cv2.imshow('display', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    cap.release()

cv2.destroyAllWindows()

我一直收到此错误,但无法解决造成此问题的原因。
gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed

最佳答案

更新:通过使用rtspsrc而不是playbin修复管道找到了答案。

Opencv的VideoCapture无法使用autovideoconvertautovideosink。解决方法是在使用rtspsrc时使用videoconvertappsink,但无法调整延迟。但是,如果要调整延迟,则需要使用decodebin进行解码,而不是avdec_h264

例如gst-launch-1.0 rtspsrc location://admin:password@192.168.1.65:554 latency=20 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! appsink
注意:管道将在python脚本中运行,但在命令行中可能无法运行。

这是用于带IP摄像机的RTSP!

干杯。

关于python - 将gstreamer管道更改为python中的opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57132682/

相关文章:

c++ - Haar Cascades 在黑暗照明中效果不佳

gstreamer - 在gstreamer中动态添加和删除T恤队列

python - Django错误 "no such column: tagging_tag.name"

python pandas - 在运行 idxmax/argmax 后获取列值

python - 查找触摸对象的轮廓作为两个不同的轮廓

python - 我无法使用 pip 在 Windows 7 上安装 python 模块 cv2

macos - mac上的gstreamer错误

Debian sid : libgstreamer dependency problems下RStudio安装失败

python - 使用 Beautiful Soup 检索结束和开始 html 标签之间的所有内容

python - 加快简单距离计算速度