Joost Rekveld
Joost Rekveld

Reputation: 81

how combine gstreamer and opencv?

I want to use OpenCV to analyze (parts of) frames taken from a webcam taken at its native resolution of 1280 by 960. I can capture these using Gstreamer and an appsink. I've come to realize, however, that merely importing OpenCV messes up Gstreamer so that my capturing does not work anymore. I need gstreamer because OpenCV only allows capturing 640x480 and I've come to like all the extra features it brings.

The most minimal example I could think of to show my problem is this:

    import gst
    from time import sleep

    #import cv2

    pipeline = gst.Pipeline()
    bin = gst.parse_bin_from_description('''
    autovideosrc !
    video/x-raw-rgb, width=1280, height=960 !
    ffmpegcolorspace !
    xvimagesink
    ''', False)
    pipeline.add(bin)

    pipeline.set_state(gst.STATE_PLAYING)

    while True:
        sleep(1)

in the version above, it runs nicely, if I uncomment the import cv2 statement, It gives me unending error messages:

libv4l2: error got 4 consecutive frame decode errors, last error: v4l-convert: error Could not enum frameival index: 6 for: RGB3 1280x960 using src: MJPG 1280x960, error: Invalid argument

I am on Kubuntu Linux 12.04, using OpenCV version 2.4.1, Gstreamer version 0.10.36

What does openCV do to mess up my Gstreamer ? How can I use both ?

Upvotes: 3

Views: 6116

Answers (4)

Mauro Lacy
Mauro Lacy

Reputation: 389

Alternatively, OpenCV (2.4.x or newer) can open GStreamer pipelines. See Using custom camera in OpenCV (via GStreamer) for an example.

OpenCV 3.0 (development branch) integrates with GStreamer 1.0.

Upvotes: 0

ensonic
ensonic

Reputation: 3450

Also, I'd recommend to refit your openCV processing into a gstreamer plugin as then you can properly schedule it.

Upvotes: 0

av501
av501

Reputation: 6739

The problem may be that gstreamer bad plugins already has opencv in it. So your opencv installation may be clashing with what version gstreamer is expecting.

Ensure you install opencv first then gstreamer if you want gstreamer to enable opencv in its build. If you do not want that do the reverse.

Upvotes: 2

Joost Rekveld
Joost Rekveld

Reputation: 81

found a workaround:

OpenCV and Gstreamer work nicely together if I lazily import OpenCV after my Gstreamer pipeline has been set up.

(in the example above that would correspond to moving the 'import cv2' statement after 'pipeline.add(bin)')

But that is not an answer I like.

Upvotes: 0

Related Questions