I am streaming a live usb camera feed from raspberry pi zero by using below code in terminal:
gst-launch-1.0 -v v4l2src device=/dev/video0 ! "image/jpeg,width=640, height=480, framerate=30/1" ! rtpjpegpay ! udpsink host=<MyRPiIPHere> port=5000
And I can get that low-latency high framerate stream from my computer (ubuntu 18.4) without any problems by using below code in terminal:
gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, encoding-name=JPEG, payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink
However, I want to get that stream using python and opencv inorder to make some operations on the image.
When I try to get image by using cv2 library with this code:
cap = cv2.VideoCapture('udpsrc port=5000 ! application/x-rtp, encoding-name=JPEG, payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink')
it doesn't catch anything. I have also tried adding various types of ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
versions to videocapture parameters.
frame
is always return None after calling ret, frame = cap.read()
.
I have installed opencv (cv2.__version__ = 3.4.0) and gstreamer (gst-launch-1.0) seperately.
I search a lot for the solution but couldn't find an easy one. I have read things like "you should build opencv with gstreamer support". How do i check if my opencv has gstreamer support and how can I build opencv with gstreamer support safely having in mind that I have both opencv and gstreamer installed on the computer (I don't mind uninstalling them but since my linux knowledge is not good one should give me step-by-step instructions :/)
Is there any solution for me to get that stream with python and cv2 library without uninstalling rebuilding opencv?
If I need to rebuild opencv with Gstreamer module support how can I safely uninstall my installed libraries and rebuild opencv?
Any help is much appreciated!