Calling Gstreamer inside openCV

2020-07-18 23:01发布

问题:

I need to call Gstremaer inside an openCV code (opening a video camera essentially). As I looked through the source code, modules/highgui/src/cap_gstreamer.cpp seems to be the file I'm looking for.

I compiled OpenCV with Gstreamer flag.

 GStreamer:
--       base:                      YES (ver 1.2.3)
--       video:                     YES (ver 1.2.3)
--       app:                       YES (ver 1.2.3)
--       riff:                      YES (ver 1.2.3)
--       pbutils:                   YES (ver 1.2.3)

but I'm not able to call a Gstreamer-related functions (e.g. cvCreateCapture_GStreamer which is defined inside cap_gstreamer.cpp) cap_gstreamer.cpp was built successfully as the opencv install log suggested:

[ 17%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_gstreamer.cpp.o

cvCreateCapture_GStreamer is also present inside /usr/local/lib/libopencv_highgui.so.3.0.0 after building openCV (found that using grep)

I use #include <opencv/highgui.h> but calling cvCreateCapture_GStreamerfails(-lopencv_highgui flag is set inside the Makefile):

error: ‘cvCapture_GStreamer’ was not declared in this scope

Any suggestions would be helpful and greatly appreciated.

Thanks!

回答1:

Actually, you can't use GStreamer API through OpenCV. What OpenCV has is a series of wrapper functions (as, for instance, cvCaptureFromCam) which implement their functionalities through external multimedia libraries. For instance, aside from GStreamer, OpenCV might use other libraries such as ffmpeg, v4l.. in fact, if you check the complete list of files related with multimedia capture through different external libraries you will find:

(in opencv/modules/highgui/src)
cap_cmu.cpp    
cap_dc1394.cpp    
cap_ffmpeg.cpp    
cap_gstreamer.cpp
...

So, if you compile OpenCV with GStreamer support, you will call the same highgui functions (as cvCaptureFromCam) but, at a low level it will be calling functions like cvCreateCapture_GStreamer which implement the calls to the GStreamer API. But it does not mean that you can call yourself to those low-level functions (hence the "was not declared in this scope" error).

Hope that it helps!

EDITED: take a look to the cap.cpp file in the opencv source. Notice the different options for CvCreateCameraCapture_XXX. It makes me think that you should be able to open your camera without some of the dependencies (by using others instead).