I'm trying to use opencv via aruco to read an UDP-Stream via Network on Ubuntu 14.04 LTS using OpenCV 3.1.0 and Gstreamer 1.2.4.
I changed the code of the "aruco_simple.cpp" Example file to accomplish that, by changing the parameter of the VideoCapturer constructor to the GStreamer Pipeline:
string PIPELINE_DEF = "udpsrc uri=udp://192.168.71.50:49152 do-timestamp=true name=src blocksize=1316 closefd=false buffer-size=100 !" \
"tsdemux !" \
"queue !" \
"avdec_h264 max-threads=0 !" \
"videoconvert !" \
"xvimagesink name=opencvsink"
//"appsink !"
;
aruco::CameraParameters CamParam;
// read the input image
cv::Mat InImage;
// Open input and read image
//VideoCapture vreader(argv[1]);
VideoCapture vreader(PIPELINE_DEF);
Executing this I always get the following Error:
OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in cvCaptureFromCAM_GStreamer, file /home/osboxes/Aruco/opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp, line 834
Exception :/home/osboxes/Aruco/opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp:834: error: (-2) GStreamer: unable to start pipeline
in function cvCaptureFromCAM_GStreamer
I found this Bug here http://code.opencv.org/issues/3953
But the solution does not help me in my case.
If I start a GStreamer Pipeline directly (without aruco and opencv) in Python it works.
GStreamer was found by opencv according to the cmake output:
-- GStreamer:
-- base: YES (ver 1.2.4)
-- video: YES (ver 1.2.4)
-- app: YES (ver 1.2.4)
-- riff: YES (ver 1.2.4)
-- pbutils: YES (ver 1.2.4)
Related
I would like to use FFMPEG as a backend for OpenCV, but I cannot get it to work.
The operating system used is CentOS8.
OpenCV and FFMPEG versions are 3.4.5 and 2.8.17, respectively.
The OpenCV build information shows that FFMPEG=ON, so OpenCV seems to recognize the FFMPEG library.
This is the video I/O part of the OpenCV build information.
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (58.91.100)
avformat: YES (58.45.100)
avutil: YES (56.51.100)
swscale: YES (5.7.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)
However, the Info message displayed at runtime says
[ INFO:0] VIDEOIO: Enabled backends(6, sorted by priority): GSTREAMER(1000); V4L2(990); CV_IMAGES(980); CV_MJPEG(970); FIREWIRE(960); UNICAP(950)
OpenCV | GStreamer warning: your gstreamer installation is missing a required plugin(/builddir/build/BUILD/opencv-3.4.6/modules/videoio/src/cap_gstreamer.cpp:1823)
OpenCV | GStreamer warning: GStreamer: unable to start pipeline(/builddir/build/BUILD/opencv-3.4.6/modules/videoio/src/cap_gstreamer.cpp:872)
I also don't understand why Gstreamer is being used when it is not enabled in the build information.
What could be the cause?
Please advise me if you know more.
Even you make the FFMPEG=ON as preference, there is no guarantee that FFMPEG will be on in the opencv build process. Because OpenCV will check for all the dependency. Please install all the dependency and try to install missing parts like GStreamer, avresample.
I'm trying to open gstreamer pipeline with opencv-python on window10 like this
cv2.VideoCapture('videotestsrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
I have installed gstreamer and test it, but VideoCapture is not open.
So I used print(cv2.getBuildInformation()) and checked gstreamer is not built like below
Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.91.100)
avformat: YES (58.45.100)
avutil: YES (56.51.100)
swscale: YES (5.7.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Media Foundation: YES
DXVA: NO
And now, I don't know how to build opencv with gstreamer.:(
I've run into this exact same frustrating problem. Fortunately, there's a handy guide to resolving it here: https://medium.com/#galaktyk01/how-to-build-opencv-with-gstreamer-b11668fa09c
In summary, you have to manually build gstreamer opencv with cmake in order to properly configure it. It takes about 1-2 hours in my experience, with 1hr compile time. Hope it works for you!
I have been trying to read videos from a file in Java using OpenCV. I am running OpenCV 4.0.0 on Ubuntu. Currently I have been trying to do so as follows:
VideoCapture videoCapture = new VideoCapture("/home/gkammer/Downloads/test.mp4");
However, this is giving me the error message VIDIOC_REQBUFS: Inappropriate ioctl for device.
I have already tried rebuilding OpenCV with FFMPEG like many similar questions recommend, but I still get the error. When I ran cmake this was the relevant output:
Video I/O:
DC1394: YES (ver 2.2.5)
FFMPEG: YES
avcodec: YES (ver 57.107.100)
avformat: YES (ver 57.83.100)
avutil: YES (ver 55.78.100)
swscale: YES (ver 4.8.100)
avresample: YES (ver 3.7.0)
GStreamer: NO
v4l/v4l2: linux/videodev2.h
Any suggestions for how to resolve this would be appreciated.
I was able to read a .mp4 video with OpenCV 4.0.1-34-g78da67947 and GStreamer 1.14.1 with Ubuntu 18.04 LTS.
To enable this video backend, install gstreamer required dependencies with:
sudo apt install libgstreamer1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good
Then recompile OpenCV with WITH_GSTREAMER flag on.
I also have issues reading mp4 video or rtsp stream with V4L or DC1364 even if I have compiled OpenCV with the correct options :
" Video I/O:
"
" DC1394: YES (2.2.5)
"
" FFMPEG: NO
"
" avcodec: NO
"
" avformat: NO
"
" avutil: NO
"
" swscale: NO
"
" avresample: NO
"
" GStreamer: YES (1.14.1)
"
" v4l/v4l2: YES (linux/videodev2.h)
If someone has a solution to this problem (specifically the DC1394 backend).
If gstreamer is not installed or there are problems with installing with sudo apt-get gstreamer-xxx, try sudo apt install ubuntu-restricted-extras.
I also have faced with this problem, then I have paid attention to the OpenCV compilation headers, installed almost all packages listed in official docs (except libjasper), cmake made it without WITH_GSTREAMER but with WITH_FFMPEG=ON and got videos with different files extensions(avi, mkv) playing on C++ and Python in Ubuntu 18.04.
Besides, explicit WITH_GSTREAMER=ON does not set flag GSTREAMER to YES.
Having already required dependencies for caffe installation:
in cmake step, when I use:
cmake ..
I get this error:
-- Python:
-- Interpreter : /home/majid/anaconda/bin/python2.7 (ver..2.7.9)
-- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
-- NumPy : /home/majid/anaconda/lib/python2.7/site-packages/numpy/core/include (ver 1.9.2)
which in Libraries it has detected wrong path instead of /home/majid/anaconda/lib/libpython2.7.so
I tried to force to use the correct path by:
cmake -D PYTHON_LIBRARY=/home/majid/anaconda/lib/libpython2.7.so ..
but after:
make all -j $(nproc)
I am getting a couple of time this warning:
At end of source: warning: routine is both "inline" and "noinline"
in the end it stops by this error:
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.8: undefined reference to `TIFFReadRGBAStrip#LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
make[2]: *** [examples/cpp_classification/classification] Error 1
make[1]: *** [examples/CMakeFiles/classification.dir/all] Error 2
make: *** [all] Error 2
while when installing opencv I used this cmake:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/majid/opencv -D PYTHON_EXECUTABLE=/home/majid/anaconda/bin/python2.7 -D PYTHON_INCLUDE_DIR=/home/majid/anaconda/include/python2.7 -D PYTHON_INCLUDE_DIRS=/home/majid/anaconda/include/python2.7 -D PYTHON_INCLUDE_DIR2=/home/majid/anaconda/include/python2.7 -D PYTHON_LIBRARIES=/home/majid/anaconda/lib/libpython2.7.so -D PYTHON_LIBRARY=/home/majid/anaconda/lib/libpython2.7.so -D PYTHON_PACKAGES_PATH=/home/majid/anaconda/lib/python2.7/site-packages -D BUILD_EXAMPLES=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D PYTHON2_LIBRARY=/home/majid/anaconda/lib/libpython2.7.so -D PYTHON_NUMPY_INCLUDE_DIRS=/home/majid/anaconda/lib/python2.7/site-packages/numpy/core/include/numpy -D BUILD_opencv_python3=OFF -D BUILD_opencv_python2=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D BUILD-TIFF=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -D WITH_GTK=ON -D MATLAB_INCLUDE_DIRS=/home/majid/MATLAB/extern/include -D MATLAB_LIBRARY_DIRS=/home/majid/MATLAB/bin -D MATLAB_MEX_SCRIPT=/home/majid/MATLAB/bin -D MATLAB_ROOT_DIR=/home/majid/MATLAB ..
in which it is: LIBTIFF=ON.
after making opencv I set the packages' path by:
export LD_LIBRARY_PATH=/home/majid/opencv/lib
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/majid/opencv/lib/pkgconfig
export PKG_CONFIG_PATH
and also:
sudo /bin/bash -c 'echo "/home/majid/opencv/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
I don't know why I am having this problem from x86-64-linux-gnu while I have the same libopencv-highgui.so in the /home/majid/opencv/lib
I really appreciate it if someone could help me out in this matter.
the result of forced cmake:
cmake -D PYTHON_LIBRARY=/home/majid/anaconda/lib/libpython2.7.so ..
-- Boost version: 1.55.0
-- Found the following Boost libraries:
-- system
-- thread
-- Found gflags (include: /usr/local/include, library: /usr/local/lib/libgflags.a)
-- Found glog (include: /usr/local/include, library: /usr/local/lib/libglog.so)
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- Found lmdb (include: /usr/local/include, library: /usr/local/lib/liblmdb.so)
-- Found LevelDB (include: /usr/local/include, library: /usr/local/lib/libleveldb.so)
-- Found Snappy (include: /usr/include, library: /usr/lib/libsnappy.so)
-- CUDA detected: 7.0
-- Found cuDNN (include: /usr/local/cuda-7.0/include, library: /usr/local/cuda-7.0/lib64/libcudnn.so)
-- Added CUDA NVCC flags for: sm_21
-- Cuda + Boost 1.55: Applying noinline work around
-- OpenCV found (/usr/share/OpenCV)
-- Found Atlas (include: /usr/include, library: /usr/lib/libatlas.so)
-- Found PythonLibs: /home/majid/anaconda/lib/libpython2.7.so (found suitable version "2.7.6", minimum required is "2.7")
-- NumPy ver. 1.9.2 found (include: /home/majid/anaconda/lib/python2.7/site-packages/numpy/core/include)
-- Boost version: 1.55.0
-- Found the following Boost libraries:
-- python
-- Detected Doxygen OUTPUT_DIRECTORY: ./doxygen/
--
-- ******************* Caffe Configuration Summary *******************
-- General:
-- Version : <TODO> (Caffe doesn't declare its version in headers)
-- Git : rc2-344-g7e5608f-dirty
-- System : Linux
-- C++ compiler : /usr/bin/c++
-- Release CXX flags : -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compared-Wno-uninitialized
-- Debug CXX flags : -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
-- Build type : Release
--
-- BUILD_SHARED_LIBS : ON
-- BUILD_python : ON
-- BUILD_matlab : OFF
-- BUILD_docs : ON
-- CPU_ONLY : OFF
--
-- Dependencies:
-- BLAS : Yes (Atlas)
-- Boost : Yes (ver. 1.55)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 3.0.0)
-- lmdb : Yes (ver. 0.9.14)
-- Snappy : Yes (ver. 1.1.0)
-- LevelDB : Yes (ver. 1.17)
-- OpenCV : Yes (ver. 2.4.8)
-- CUDA : Yes (ver. 7.0)
--
-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_21
-- cuDNN : Yes
--
-- Python:
-- Interpreter : /home/majid/anaconda/bin/python2.7 (ver. 2.7.9)
-- Libraries : /home/majid/anaconda/lib/libpython2.7.so (ver 2.7.6)
-- NumPy : /home/majid/anaconda/lib/python2.7/site-packages/numpy/core/include (ver 1.9.2)
--
-- Documentaion:
-- Doxygen : /usr/bin/doxygen (1.8.6)
-- config_file : /home/majid/caffe/.Doxyfile
--
-- Install:
-- Install path : /home/majid/caffe/build/install
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/majid/caffe/build
I'm writing a Python program using OpenCV, but I cannot capture images from v4l2 cameras.
I tried with both a PS2 EyeToy and Droidcam (Android virtual webcam), which are both using v4l2, and none of them work: cv.CaptureFromCAM(0) only returns None.
I can use both webcams in other programs (tried VLC and Kamerka).
I guess that OpenCV supports v4l only, not v4l2.
How can I solve this problem? Does a v4l2->v4l converter exist?
EDIT: I read that cv.CaptureFromFile uses ffmpeg to decode video files. Is it possible to manually specify a format, so I can use ffmpeg's video4linux2 demuxer?
For OpenCV 3.2.0, including the following in the cmake options worked for me
from https://github.com/opencv/opencv/issues/7974
-DWITH_V4L=ON
-DWITH_LIBV4L=ON
I'm less sure if this one had an affect, but from VideoCapture Does Not Work in Anaconda
-DWITH_FFMPEG=1
Including all 3 in my cmake options seemed to be what finally made mine work
OpenCV does support V4L2, but maybe not by default.
Download OpenCV's source code and make sure you have v4l2 headers and libraries installed on your system.
After configuring OpenCV with cmake, check it's output:
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: YES (ver 2.2.0)
-- FFMPEG: YES
-- codec: YES (ver Unknown)
-- format: YES (ver Unknown)
-- util: YES (ver Unknown)
-- swscale: YES (ver Unknown)
-- gentoo-style: YES
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- QuickTime: NO
-- QTKit: YES
-- V4L/V4L2: NO/NO
If you notice the output above, OpenCV won't be build with support to V4L/V4L2 on my system because I don't have the necessary development files installed.
I had to update the permissions of the camera, then OpenCV started working for me.
sudo chmod 0777 /dev/video0