8

I'm trying to have OpenCV process a frame in the middle of a gstreamer pipe.

I have one gstreamer pipe generating the stream, sending it to appsink for OpenCV code to receive:

v4l2src ! ffmpegcolorspace ! jpegenc ! appsink name=sink

And another pipe getting it from appsrc (to which OpenCV sends data) and outputting it on the screen:

appsrc name=src ! jpegdec ! xvimagesink

I open every frame with a pull-buffer request on sink and process it with OpenCV, then use push-buffer on src. I am doing all that in Python.

For some reason, that does not seem to work (segmentation fault).

But I'm not really trying to fix it; it's terribly inefficient anyway. I am just wondering whether there any better way to have OpenCV process the frame before it reaches an output sink?

SMiLE
  • 1,073
  • 1
  • 9
  • 8
  • 2
    Since you want more than what gst-opencv can offer, if you don't mind writing your logic in C (or C++), perhaps you should try writing it as a plugin to gst? You can take one of the gst-opencv plugins' source as a starting point – sinelaw Jan 14 '11 at 03:21
  • 1
    Another thing - your example seems to just grabbing from v4l2, and I think opencv's HighGui API supports that already (or at least v4l without the '2'). that would be the easiest solution if you don't really need gstreamer. – sinelaw Jan 14 '11 at 03:23
  • 1. Good suggestion, I might do that. 2. You're right, I could use HighGUI in this case, but v4l2src was used merely as an example. In the actual application I intend to get the video stream from a tcp source, so I can't really implement the whole thing in OpenCV. – SMiLE Jan 14 '11 at 03:40

2 Answers2

3

Did you try gst-opencv? It supplies several opencv primitives as gstreamer plugins.

EDIT: Seems like it's merged into gst-plugins-bad, and the link above is outdated.

sinelaw
  • 16,205
  • 3
  • 49
  • 80
  • Thanks for your answer. I considered gst-opencv but decided against it because I want the freedom to process the video frames in any way I want (for example, apply domain-specific machine learning algorithms), and the options offered by gst-opencv are very generic. – SMiLE Jan 14 '11 at 03:01
1

I know some years have passed since your original question, but just for the record, OpenCv can open Gstreamer pipelines directly. See the (self-)answer in Using custom camera in OpenCV (via GStreamer) for an example.

And, by the way, OpenCv 3.0 (master branch) actually integrates gstreamer 1.0 support.

Community
  • 1
  • 1
Mauro Lacy
  • 389
  • 2
  • 8