How can I stream the output of my OpenCV python script (running on a RaspPi) to my computer?

asked 2018-06-29 15:39:17 -0600

kasool gravatar image

Hi I have a Raspberry Pi running an OpenCV script I wrote in python that recognizes and highlights colored round objects. I can easily view the raw video stream of the Pi Camera using VLC player, but I need the output video (with the highlighted objects) of my OpenCV script instead.

After much research it seems GStreamer is what I need, but hours of internet search have yielded very little example code of how I can implement it. This is the relevant parts of my python script:

import cv2
from PiVideoStream import PiVideoStream

vs = PiVideoStream().start()

out = cv2.VideoWriter('appsrc ! videoconvert ! ''x264enc noise-reduction=10000 speed-preset=ultrafast tune=zerolatency ! ''rtph264pay config-interval=1 pt=96 !''tcpserversink host=INSERT.IP.HERE port=5000 sync=false', 0, 32.0, (320, 240))


while True:
    frame = vs.read()
    """OpenCV algorithm that is irrelevant"""
    out.write(frame)
    key = cv2.waitKey(1) & 0xFFif key == lord("q"):
        breakout.release()
vs.release()
cv2.destroyAllWindows()

And from my understanding, I need to start the Gstreamer pipeline which I do this:

gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host = INSERT.IP.HERE port=5000
  1. Should INSERT.IP.HERE be the IP of my computer I want to view the stream on? Or of my raspberry pi?
  2. I've tried using VLC player to view the stream at tcp://INSERT.IP.HERE:5000/ to no avail, is this the proper way to view?
  3. Do I need to enable the Gstreamer plugin for my build of OpenCV? cv2.getBuildInformation() currently has "NO" on GStreamer, but I assumed this was separate from simply installing GStream on my Pi?
edit retag flag offensive close merge delete

Comments

"cv2.getBuildInformation() currently has "NO" on GStreamer," -- this means, you have to rebuild it from src, with gstreamer support enabled. installing anything later won't help.

berak gravatar imageberak ( 2018-06-30 00:27:05 -0600 )edit

I see, are the other parts of my code alright though? Assuming I successfully rebuild opencv?

kasool gravatar imagekasool ( 2018-07-02 08:36:20 -0600 )edit

2.: for a server, you usually use ip 0.0.0.0 (to acces it from a client, you need the real ip)

in the meantime, you could also try a "toy solution", like this

berak gravatar imageberak ( 2018-07-02 08:44:17 -0600 )edit