Search code examples
pythonc++opencvgstreamerpython-gstreamer

Python with Gstreamer pipeline


I'm working on an Udoo trying to get the camera to take a picture that I can manipulate inside Python.

So far, the camera works with

gst-launch-1.0 imxv4l2videosrc ! imxipuvideosink

I can also take a single picture with

gst-launch-1.0 imxv4l2videosrc num-buffers=1 ! video/x-raw ! jpegenc ! filesink location=output.jpg

From here it seems like you can read straight from a gstreamer stream in Python with OpenCV.

Here is my python code:

import cv2
cam = cv2.VideoCapture("imxv4l2videosrc ! video/x-raw ! appsink")
ret, image = cam.read()

However, ret is False, and image is nothing.

Some places say this only works with OpenCV 3.0+, and others say 2.4.x, but I can't seem to find an actual answer to what version it works on.

If I need to update to OpenCV 3.0, which part to I update? I downloaded OpenCV via the apt repositories under the package python-opencv. So do I need to update Python? Can I just build OpenCV from source, and Python will automatically be using the newest version? I'm so confused.


Solution

  • The Ubuntu/Debian version is old 2.4.x, to get the last one you need to compile it from source.

    Here two tutorials on how to do that:

    1. https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.html#installing-opencv-from-source
    2. http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/

    The first is for Python 2.7 on Fedora, the second for Python 3.4 on Ubuntu.