Follow http://www.ozbotz.org/opencv-installation/ and http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/
I downloaded the latest versions of ffmpeg, v4l and x264 libs
- ffmpeg-3.1.3.tar.bz2
- v4l-utils-1.10.1.tar.bz2
- x264-snapshot-20160910-2245-stable.tar.bz2
OpenCV when compiled with default libgphoto2 installed on Ubuntu 12.04 gives error. As described here
The same problem is also discussed on this SO question.
Solution: Manually compile and install gphoto2 and libgphoto2. Download gphoto and libgphoto2 from here
- gphoto2-2.5.10.tar.bz2
- libgphoto2-2.5.10.tar.bz2
Download opencv and opencv_contrib packages
- opencv-3.1.0.tar.gz
- opencv_contrib-3.1.0.tar.gz
tar xvzf opencv-3.1.0.tar.gz
tar xvzf opencv_contrib-3.1.0.tar.gz
cd opencv-3.1.0
mkdir build && cd build
Run cmake to configure and generate makefile. I configured to compile opencv without hdf module. Because the default libhdf5 gives error. This can probably be fixed by installing latest libhdf5 from source but I didn't try.
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
# change below directory to where you have extracted opencv contrib zipped file
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.1.0/modules/ \
-D BUILD_EXAMPLES=ON \
-D WITH_CUDA=OFF \ # I installed without Cuda. Remove this if you want to compile cuda modules
-D BUILD_opencv_hdf=OFF \
..
If linux/videodev2.h and linux/videodev.h not found
sudo apt-get install libv4l-dev
cd /usr/include/linux
sudo ln -s ../libv4l1-videodev.h videodev.h
If cmake gives following error:
CMake Error at samples/gpu/CMakeLists.txt:100 (list):
list sub-command REMOVE_ITEM requires list to be present
There are two ways to resolve this error:
- run cmake with INSTALL_C_EXAMPLES=OFF
- edit line#100 of samples/gpu/CMakeLists.txt from
list(REMOVE_ITEM all_samples "opengl.cpp")
tolist(REMOVE_ITEM install_list "opengl.cpp")
This was a bug in opencv-3.1.0. It was discussed in issue 5851 and fixed in this commit. You can check that the same change was made in the commit too.
Now we can run cmake with INSTALL_C_EXAMPLES=ON
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
# change below directory to where you have extracted opencv contrib zipped file
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.1.0/modules/ \
-D BUILD_EXAMPLES=ON \
-D WITH_CUDA=OFF \ # I installed without Cuda. Remove this if you want to compile cuda modules
-D BUILD_opencv_hdf=OFF \
..
make -j4
sudo make install
To remove warning - "libdc1394 error: Failed to initialize libdc1394"
- source: http://stackoverflow.com/q/29274638/925216
- source: http://stackoverflow.com/q/12689304/925216
sudo ln /dev/null /dev/raw1394
or - source: http://stackoverflow.com/a/39541989/925216
CMAKE with -D WITH_1394=OFF
While installing opencv 3.1.0 on Ubuntu 16.04 with hdf5 support:
Modify the file /opencv_contrib-3.1.0/modules/hdf/include/opencv2/hdf/hdf5.hpp in line 40:
--- #include
+++ #include "/usr/include/hdf5/serial/hdf5.h"
source