Compiling/Building OpenCV under Ubuntu/Debian

Downloading the required packages

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

Cloning the repository

While in home directory (or wherever you want) clone the OpenCV repository

git clone https://github.com/opencv/opencv.git



Building/Compiling the OpenCV

Accesses the opencv folder just cloned from the OpenCV repository,  creates a folder called release and generates the Makefile, it should take between 30 seconds to a minute

cd opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

Building the library, it should take around 30 minutes

make
sudo make install

 

Something similar will be output, you can find the path inside

-- Installing: /usr/local/lib/libopencv_superres.so
-- Installing: /usr/local/include/opencv2/superres.hpp
-- Installing: /usr/local/include/opencv2/superres/optical_flow.hpp
-- Installing: /usr/local/lib/libopencv_features2d.so.3.3.0
-- Installing: /usr/local/lib/libopencv_features2d.so.3.3
-- Set runtime path of "/usr/local/lib/libopencv_features2d.so.3.3.0" to "/usr/local/lib"
-- Installing: /usr/local/lib/libopencv_features2d.so
-- Installing: /usr/local/include/opencv2/features2d.hpp
-- Installing: /usr/local/include/opencv2/features2d/features2d.hpp
-- Installing: /usr/local/lib/libopencv_calib3d.so.3.3.0
-- Installing: /usr/local/lib/libopencv_calib3d.so.3.3
-- Set runtime path of "/usr/local/lib/libopencv_calib3d.so.3.3.0" to "/usr/local/lib"
-- Installing: /usr/local/lib/libopencv_calib3d.so
-- Installing: /usr/local/include/opencv2/calib3d.hpp
-- Installing: /usr/local/include/opencv2/calib3d/calib3d.hpp
-- Installing: /usr/local/include/opencv2/calib3d/calib3d_c.h
-- Installing: /usr/local/lib/libopencv_stitching.so.3.3.0
-- Installing: /usr/local/lib/libopencv_stitching.so.3.3
-- Set runtime path of "/usr/local/lib/libopencv_stitching.so.3.3.0" to "/usr/local/lib"
-- Installing: /usr/local/lib/libopencv_stitching.so
-- Installing: /usr/local/include/opencv2/stitching.hpp
-- Installing: /usr/local/include/opencv2/stitching/warpers.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/autocalib.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/blenders.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/camera.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/exposure_compensate.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/matchers.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/motion_estimators.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/seam_finders.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/timelapsers.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/util.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/util_inl.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/warpers.hpp
-- Installing: /usr/local/include/opencv2/stitching/detail/warpers_inl.hpp
-- Installing: /usr/local/lib/libopencv_videostab.so.3.3.0
-- Installing: /usr/local/lib/libopencv_videostab.so.3.3
-- Set runtime path of "/usr/local/lib/libopencv_videostab.so.3.3.0" to "/usr/local/lib"
-- Installing: /usr/local/lib/libopencv_videostab.so
-- Installing: /usr/local/include/opencv2/videostab.hpp
-- Installing: /usr/local/include/opencv2/videostab/deblurring.hpp
-- Installing: /usr/local/include/opencv2/videostab/fast_marching.hpp
-- Installing: /usr/local/include/opencv2/videostab/fast_marching_inl.hpp
-- Installing: /usr/local/include/opencv2/videostab/frame_source.hpp
-- Installing: /usr/local/include/opencv2/videostab/global_motion.hpp
-- Installing: /usr/local/include/opencv2/videostab/inpainting.hpp
-- Installing: /usr/local/include/opencv2/videostab/log.hpp
-- Installing: /usr/local/include/opencv2/videostab/motion_core.hpp
-- Installing: /usr/local/include/opencv2/videostab/motion_stabilizing.hpp
-- Installing: /usr/local/include/opencv2/videostab/optical_flow.hpp
-- Installing: /usr/local/include/opencv2/videostab/outlier_rejection.hpp
-- Installing: /usr/local/include/opencv2/videostab/ring_buffer.hpp
-- Installing: /usr/local/include/opencv2/videostab/stabilizer.hpp
-- Installing: /usr/local/include/opencv2/videostab/wobble_suppression.hpp
-- Installing: /usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so
-- Set runtime path of "/usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so" to "/usr/local/lib"
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_frontalcatface.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_frontalcatface_extended.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt_tree.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_fullbody.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_lefteye_2splits.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_licence_plate_rus_16stages.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_lowerbody.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_profileface.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_righteye_2splits.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_russian_plate_number.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_smile.xml
-- Installing: /usr/local/share/OpenCV/haarcascades/haarcascade_upperbody.xml
-- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalcatface.xml
-- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalface.xml
-- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalface_improved.xml
-- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_profileface.xml
-- Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_silverware.xml
-- Installing: /usr/local/bin/opencv_traincascade
-- Set runtime path of "/usr/local/bin/opencv_traincascade" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_createsamples
-- Set runtime path of "/usr/local/bin/opencv_createsamples" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_annotation
-- Set runtime path of "/usr/local/bin/opencv_annotation" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_visualisation

Here are interesting uses for OpenCV

If you have any questions or suggestions, feel free to leave a comment.

Become a Patron!