python opencv 显示 gstreamer videotestsrc

Ted*_*y_R 5 python linux opencv gstreamer

我需要使用 GStreamer 将数据传递到一些 OpenCV/Cuda 分类和深度学习系统。

问题是我对 GStreamer 和 Cuda 很陌生,所以我需要制作一些简单的示例,结合尽可能少的元素 - 这里是 OpenCV 和 Gstreamer。

cv.imshow()现在我只希望 GStreamer在循环中将“videotestsrc pattern=ball”传递到一帧一帧

问题是我似乎无法打开该cv.VideoCapture()元素 - 正确地因为管道错误

我已经花了几个小时了,现在已经“放弃”了

OpenCV 是 v3.4.0 - 使用 GStreamer 支持编译 Python 是 3.6.8

这是我现在的代码 -

我用谷歌搜索了一遍,并尝试了许多管道组合,但没有任何东西能让我打开视频捕获元素

#!/usr/bin/env python3
import cv2 as cv

cap = cv.VideoCapture("videotestsrc ! video/x-raw,framerate=20/1 ! appsink", cv.CAP_GSTREAMER)

# Commented out to continue to capture
# Evaluates true => app closes
#if not cap.isOpened():
#    print('VideoCapture not opened')
#    exit(0)

while(True):
    ret, frame = cap.read()
    print(ret)     # 'False' when run
    print(frame)   # 'None' when run

    cv.imshow('frame',frame)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

cap.isOpened()回报False

cap.read()回报False, None