|
| 1 | +Installation in MacOS {#tutorial_macos_install} |
| 2 | +===================== |
| 3 | + |
| 4 | +The following steps have been tested for MacOSX (Mavericks) but should work with other versions as well. |
| 5 | + |
| 6 | +Required Packages |
| 7 | +----------------- |
| 8 | + |
| 9 | +- CMake 3.9 or higher |
| 10 | +- Git |
| 11 | +- Python 2.7 or later and Numpy 1.5 or later |
| 12 | + |
| 13 | +This tutorial will assume you have [Python](https://docs.python.org/3/using/mac.html), |
| 14 | +[Numpy](https://docs.scipy.org/doc/numpy-1.10.1/user/install.html) and |
| 15 | +[Git](https://www.atlassian.com/git/tutorials/install-git) installed on your machine. |
| 16 | + |
| 17 | +@note |
| 18 | +OSX comes with Python 2.7 by default, you will need to install Python 3.8 if you want to use it specifically. |
| 19 | + |
| 20 | +@note |
| 21 | +If you XCode and XCode Command Line-Tools installed, you already have git installed on your machine. |
| 22 | + |
| 23 | +Installing CMake |
| 24 | +---------------- |
| 25 | +-# Find the version for your system and download CMake from their release's [page](https://cmake.org/download/) |
| 26 | + |
| 27 | +-# Install the dmg package and launch it from Applications. That will give you the UI app of CMake |
| 28 | + |
| 29 | +-# From the CMake app window, choose menu Tools --> Install For Command Line Use. |
| 30 | + |
| 31 | +-# Install folder will be /usr/bin/ by default, submit it by choosing Install command line links. |
| 32 | + |
| 33 | +-# Test that it works by running |
| 34 | + @code{.bash} |
| 35 | + cmake --version |
| 36 | + @endcode |
| 37 | + |
| 38 | +Getting OpenCV Source Code |
| 39 | +-------------------------- |
| 40 | + |
| 41 | +You can use the latest stable OpenCV version or you can grab the latest snapshot from our |
| 42 | +[Git repository](https://github.com/opencv/opencv.git). |
| 43 | + |
| 44 | +### Getting the Latest Stable OpenCV Version |
| 45 | + |
| 46 | +- Go to our [downloads page](http://opencv.org/releases.html). |
| 47 | +- Download the source archive and unpack it. |
| 48 | + |
| 49 | +### Getting the Cutting-edge OpenCV from the Git Repository |
| 50 | + |
| 51 | +Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv). |
| 52 | +If you need modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well. |
| 53 | + |
| 54 | +For example |
| 55 | +@code{.bash} |
| 56 | +cd ~/<my_working_directory> |
| 57 | +git clone https://github.com/opencv/opencv.git |
| 58 | +git clone https://github.com/opencv/opencv_contrib.git |
| 59 | +@endcode |
| 60 | +Building OpenCV from Source Using CMake |
| 61 | +--------------------------------------- |
| 62 | + |
| 63 | +-# Create a temporary directory, which we denote as `<cmake_build_dir>`, where you want to put |
| 64 | + the generated Makefiles, project files as well the object files and output binaries and enter |
| 65 | + there. |
| 66 | + |
| 67 | + For example |
| 68 | + @code{.bash} |
| 69 | + mkdir build_opencv |
| 70 | + cd build_opencv |
| 71 | + @endcode |
| 72 | + |
| 73 | + @note It is good practice to keep clean your source code directories. Create build directory outside of source tree. |
| 74 | + |
| 75 | +-# Configuring. Run `cmake [<some optional parameters>] <path to the OpenCV source directory>` |
| 76 | + |
| 77 | + For example |
| 78 | + @code{.bash} |
| 79 | + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ../opencv |
| 80 | + @endcode |
| 81 | + |
| 82 | + or cmake-gui |
| 83 | + |
| 84 | + - set full path to OpenCV source code, e.g. `/home/user/opencv` |
| 85 | + - set full path to `<cmake_build_dir>`, e.g. `/home/user/build_opencv` |
| 86 | + - set optional parameters |
| 87 | + - run: "Configure" |
| 88 | + - run: "Generate" |
| 89 | + |
| 90 | +-# Description of some parameters |
| 91 | + - build type: `CMAKE_BUILD_TYPE=Release` (or `Debug`) |
| 92 | + - to build with modules from opencv_contrib set `OPENCV_EXTRA_MODULES_PATH` to `<path to |
| 93 | + opencv_contrib>/modules` |
| 94 | + - set `BUILD_DOCS=ON` for building documents (doxygen is required) |
| 95 | + - set `BUILD_EXAMPLES=ON` to build all examples |
| 96 | + |
| 97 | +-# [optional] Building python. Set the following python parameters: |
| 98 | + - `PYTHON3_EXECUTABLE = <path to python>` |
| 99 | + - `PYTHON3_INCLUDE_DIR = /usr/include/python<version>` |
| 100 | + - `PYTHON3_NUMPY_INCLUDE_DIRS = |
| 101 | + /usr/lib/python<version>/dist-packages/numpy/core/include/` |
| 102 | + @note |
| 103 | + To specify Python2 versions, you can replace `PYTHON3_` with `PYTHON2_` in the above parameters. |
| 104 | + |
| 105 | +-# Build. From build directory execute *make*, it is recommended to do this in several threads |
| 106 | + |
| 107 | + For example |
| 108 | + @code{.bash} |
| 109 | + make -j7 # runs 7 jobs in parallel |
| 110 | + @endcode |
| 111 | + |
| 112 | +-# To use OpenCV in your CMake-based projects through `find_package(OpenCV)` specify `OpenCV_DIR=<path_to_build_or_install_directory>` variable. |
| 113 | + |
| 114 | +@note |
| 115 | +You can also use a package manager like [Homebrew](https://brew.sh/) |
| 116 | +or [pip](https://pip.pypa.io/en/stable/) to install releases of OpenCV only (Not the cutting edge). |
0 commit comments