1 Installation in MacOS {#tutorial_macos_install}
4 @prev_tutorial{tutorial_android_ocl_intro}
5 @next_tutorial{tutorial_ios_install}
8 The following steps have been tested for MacOSX (Mavericks) but should work with other versions as well.
15 - Python 2.7 or later and Numpy 1.5 or later
17 This tutorial will assume you have [Python](https://docs.python.org/3/using/mac.html),
18 [Numpy](https://docs.scipy.org/doc/numpy-1.10.1/user/install.html) and
19 [Git](https://www.atlassian.com/git/tutorials/install-git) installed on your machine.
22 OSX comes with Python 2.7 by default, you will need to install Python 3.8 if you want to use it specifically.
25 If you XCode and XCode Command Line-Tools installed, you already have git installed on your machine.
29 -# Find the version for your system and download CMake from their release's [page](https://cmake.org/download/)
31 -# Install the dmg package and launch it from Applications. That will give you the UI app of CMake
33 -# From the CMake app window, choose menu Tools --> Install For Command Line Use.
35 -# Install folder will be /usr/bin/ by default, submit it by choosing Install command line links.
37 -# Test that it works by running
42 Getting OpenCV Source Code
43 --------------------------
45 You can use the latest stable OpenCV version or you can grab the latest snapshot from our
46 [Git repository](https://github.com/opencv/opencv.git).
48 ### Getting the Latest Stable OpenCV Version
50 - Go to our [downloads page](http://opencv.org/releases.html).
51 - Download the source archive and unpack it.
53 ### Getting the Cutting-edge OpenCV from the Git Repository
55 Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv).
56 If you need modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well.
60 cd ~/<my_working_directory>
61 git clone https://github.com/opencv/opencv.git
62 git clone https://github.com/opencv/opencv_contrib.git
64 Building OpenCV from Source Using CMake
65 ---------------------------------------
67 -# Create a temporary directory, which we denote as `<cmake_build_dir>`, where you want to put
68 the generated Makefiles, project files as well the object files and output binaries and enter
77 @note It is good practice to keep clean your source code directories. Create build directory outside of source tree.
79 -# Configuring. Run `cmake [<some optional parameters>] <path to the OpenCV source directory>`
83 cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ../opencv
88 - set full path to OpenCV source code, e.g. `/home/user/opencv`
89 - set full path to `<cmake_build_dir>`, e.g. `/home/user/build_opencv`
90 - set optional parameters
94 -# Description of some parameters
95 - build type: `CMAKE_BUILD_TYPE=Release` (or `Debug`)
96 - to build with modules from opencv_contrib set `OPENCV_EXTRA_MODULES_PATH` to `<path to
97 opencv_contrib>/modules`
98 - set `BUILD_DOCS=ON` for building documents (doxygen is required)
99 - set `BUILD_EXAMPLES=ON` to build all examples
101 -# [optional] Building python. Set the following python parameters:
102 - `PYTHON3_EXECUTABLE = <path to python>`
103 - `PYTHON3_INCLUDE_DIR = /usr/include/python<version>`
104 - `PYTHON3_NUMPY_INCLUDE_DIRS =
105 /usr/lib/python<version>/dist-packages/numpy/core/include/`
107 To specify Python2 versions, you can replace `PYTHON3_` with `PYTHON2_` in the above parameters.
109 -# Build. From build directory execute *make*, it is recommended to do this in several threads
113 make -j7 # runs 7 jobs in parallel
116 -# To use OpenCV in your CMake-based projects through `find_package(OpenCV)` specify `OpenCV_DIR=<path_to_build_or_install_directory>` variable.
119 You can also use a package manager like [Homebrew](https://brew.sh/)
120 or [pip](https://pip.pypa.io/en/stable/) to install releases of OpenCV only (Not the cutting edge).