2

How can I tell whether or not the version of OpenCV shipped with Ubuntu 12.04 supports v4l2 devices? I have found a number of (oldish) pages that say OpenCV does support v4l2, but it's not clear to me whether the version installed on my 12.04 box was compiled with the appropriate option to enable this.

Needless to say, I'm having difficulty capturing images from a v4l2 camera using the python bindings for openCV. I'm trying to figure out where things are falling apart.

1 Answer 1

3

It does not! You have to build OpenCV with v4l support yourself.

Script (save it as opencv2_4_5.sh, make it executable and run it) (includes v4l somewhere in the middle)(other versions are available on that site).

arch=$(uname -m)
if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
flag=1
else
flag=0
fi
echo "Installing OpenCV 2.4.5"
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get -y remove ffmpeg x264 libx264-dev
echo "Installing Dependenices"
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libtbb-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
echo "Downloading OpenCV 2.4.5"
wget -O OpenCV-2.4.5.tar.gz http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.5/opencv-2.4.5.tar.gz/download
echo "Installing OpenCV 2.4.5"
tar -xvf OpenCV-2.4.5.tar.gz
cd opencv-2.4.5
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j4
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
echo "OpenCV 2.4.5 ready to be used"
3
  • not my script ;)
    – Rinzwind
    Sep 16, 2013 at 20:20
  • Well, it still worked :-) Thanks for pointing me at it. Sep 16, 2013 at 22:03
  • I would add some kind of warnings to that script, just ran it and seems its replacing my fglrx drivers with nvidia 319_updates even when I don't have any Nvidia graphics card and was plenty happy with my fglrx drivers for my RadeonHD 7750 :S
    – Allu2
    Dec 9, 2013 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .