python opencv display gstreamer videotestsrc

Viewed 387

I need to use GStreamer to deliver data to some OpenCV/Cuda classification and deep-learning systems.

The problem is that I'm new to the GStreamer and the Cuda, so I need to make some simple examples that combine as few elements as possible - here OpenCV and Gstreamer.

Now I only want GStreamer to deliver the "videotestsrc pattern=ball" to a cv.imshow() frame by frame in a loop

The problem is that I don't seem to be able to open the cv.VideoCapture() element - Properly because pipeline is wrong

I have spent several hours now and have "given up"

OpenCV is v3.4.0 - Compiled with GStreamer support Python is 3.6.8

This is the code I have now -

I have googled and googled and tried many pipeline combination, but nothing enables me to open the videocapture element

#!/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()

cap.isOpened() returns False

cap.read() returns False, None

0 Answers
Related