sudo apt install ffmpeg sudo apt install libgtk-3-dev sudo apt install libv4l-dev sudo apt install libtiff-dev sudo apt install libwebp-dev sudo apt install libpng-dev sudo apt install libjpeg-dev sudo apt install libopenexr-dev sudo apt install default-jdk sudo apt-get install libblas-dev liblapack-dev sudo apt install libopus-dev libmp3lame-dev libfdk-aac-dev libvpx-dev libx264-dev yasm libass-dev libtheora-dev libvorbis-dev sudo apt install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
As a start https://docs.opencv.org/3.4.1/d2/de6/tutorial_py_setup_in_ubuntu.html but this uses pure default locations. I have my own python builds in $HOME/sw
I like to create a directory based on the build date
mkdir build-2018-10-28
cd build-2018-10-28
to try different flags, you have to remove this file:
rm CMakeCache.txt
Then run cmake. cmake does not keep a copy of the command used to generate the build so make sure you save your history for future use
cmake \
-D CMAKE_INSTALL_PREFIX=$HOME/sw \
-D OPENCV_EXTRA_MODULES_PATH=$HOME/sw/opencv_contrib/modules \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_opencv_python3=ON \
-D HAVE_opencv_python3=ON \
..
To disable build for python 2, use this cmake
cmake -D CMAKE_INSTALL_PREFIX=$HOME/sw \
-D OPENCV_EXTRA_MODULES_PATH=$HOME/sw/opencv_contrib/modules \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_opencv_python3=ON \
-D HAVE_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
..
https://askubuntu.com/questions/783956/how-to-install-opencv-3-1-for-python-3-5-on-ubuntu-16-04-lts