Skip to content

Commit 3d91d75

Browse files
authored
Merge pull request opencv#26564 from shyama7004:improve-macos-install-docs
Improvement of macOS installation guide in documentation opencv#26564 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent 23fcea0 commit 3d91d75

File tree

1 file changed

+94
-39
lines changed

1 file changed

+94
-39
lines changed

doc/tutorials/introduction/macos_install/macos_install.markdown

Lines changed: 94 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,49 @@ Installation in MacOS {#tutorial_macos_install}
99
| Original author | `@sajarindider` |
1010
| Compatibility | OpenCV >= 3.4 |
1111

12-
The following steps have been tested for MacOSX (Mavericks) but should work with other versions as well.
12+
The following steps have been tested for macOS (Mavericks) but should work with other versions as well.
1313

1414
Required Packages
1515
-----------------
1616

1717
- CMake 3.9 or higher
1818
- Git
19-
- Python 2.7 or later and Numpy 1.5 or later
19+
- Python 3.x and NumPy 1.5 or later
2020

2121
This tutorial will assume you have [Python](https://docs.python.org/3/using/mac.html),
22-
[Numpy](https://docs.scipy.org/doc/numpy-1.10.1/user/install.html) and
23-
[Git](https://www.atlassian.com/git/tutorials/install-git) installed on your machine.
22+
[NumPy](https://numpy.org/install/) and
23+
[Git](https://git-scm.com/downloads/mac) installed on your machine.
2424

2525
@note
26-
OSX comes with Python 2.7 by default, you will need to install Python 3.8 if you want to use it specifically.
26+
- macOS up to 12.2 (Monterey): Comes with Python 2.7 pre-installed.
27+
- macOS 12.3 and later: Python 2.7 has been removed, and no version of Python is included by default.
28+
29+
It is recommended to install the latest version of Python 3.x (at least Python 3.8) for compatibility with the latest OpenCV Python bindings.
2730

2831
@note
29-
If you XCode and XCode Command Line-Tools installed, you already have git installed on your machine.
32+
If you have Xcode and Xcode Command Line Tools installed, Git is already available on your machine.
3033

3134
Installing CMake
3235
----------------
3336
-# Find the version for your system and download CMake from their release's [page](https://cmake.org/download/)
3437

35-
-# Install the dmg package and launch it from Applications. That will give you the UI app of CMake
38+
-# Install the `.dmg` package and launch it from Applications. That will give you the UI app of CMake
3639

3740
-# From the CMake app window, choose menu Tools --> How to Install For Command Line Use. Then, follow the instructions from the pop-up there.
3841

39-
-# Install folder will be /usr/bin/ by default, submit it by choosing Install command line links.
42+
-# The install folder will be `/usr/local/bin/` by default. Complete the installation by choosing Install command line links.
43+
44+
-# Test that CMake is installed correctly by running:
4045

41-
-# Test that it works by running
4246
@code{.bash}
4347
cmake --version
4448
@endcode
4549

46-
@note You can use [Homebrew](https://brew.sh/) to install CMake with @code{.bash} brew install cmake @endcode
50+
@note You can use [Homebrew](https://brew.sh/) to install CMake with:
51+
52+
@code{.bash}
53+
brew install cmake
54+
@endcode
4755

4856
Getting OpenCV Source Code
4957
--------------------------
@@ -53,74 +61,121 @@ You can use the latest stable OpenCV version or you can grab the latest snapshot
5361

5462
### Getting the Latest Stable OpenCV Version
5563

56-
- Go to our [downloads page](https://opencv.org/releases).
57-
- Download the source archive and unpack it.
64+
- Go to our [OpenCV releases page](https://opencv.org/releases).
65+
- Download the source archive of the latest version (e.g., OpenCV 4.x) and unpack it.
5866

5967
### Getting the Cutting-edge OpenCV from the Git Repository
6068

61-
Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv).
62-
If you need modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well.
69+
Launch Git client and clone [OpenCV repository](https://github.com/opencv/opencv).
70+
If you need modules from [OpenCV contrib repository](https://github.com/opencv/opencv_contrib) then clone it as well.
71+
72+
For example:
73+
74+
@code{.bash}
75+
cd ~/<your_working_directory>
76+
git clone https://github.com/opencv/opencv.git
77+
git clone https://github.com/opencv/opencv_contrib.git
78+
@endcode
6379

64-
For example
65-
@code{.bash}
66-
cd ~/<my_working_directory>
67-
git clone https://github.com/opencv/opencv.git
68-
git clone https://github.com/opencv/opencv_contrib.git
69-
@endcode
7080
Building OpenCV from Source Using CMake
7181
---------------------------------------
7282

7383
-# Create a temporary directory, which we denote as `build_opencv`, where you want to put
7484
the generated Makefiles, project files as well the object files and output binaries and enter
7585
there.
7686

77-
For example
87+
For example:
88+
7889
@code{.bash}
7990
mkdir build_opencv
8091
cd build_opencv
8192
@endcode
8293

83-
@note It is good practice to keep clean your source code directories. Create build directory outside of source tree.
94+
@note It is good practice to keep your source code directories clean. Create the build directory outside of the source tree.
8495

8596
-# Configuring. Run `cmake [<some optional parameters>] <path to the OpenCV source directory>`
8697

87-
For example
98+
For example:
99+
88100
@code{.bash}
89101
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ../opencv
90102
@endcode
91103

92-
or cmake-gui
104+
Alternatively, you can use the CMake GUI (`cmake-gui`):
93105

94-
- set the OpenCV source code path to, e.g. `/home/user/opencv`
95-
- set the binary build path to your CMake build directory, e.g. `/home/user/build_opencv`
106+
- set the OpenCV source code path to, e.g. `/Users/your_username/opencv`
107+
- set the binary build path to your CMake build directory, e.g. `/Users/your_username/build_opencv`
96108
- set optional parameters
97109
- run: "Configure"
98110
- run: "Generate"
99111

100112
-# Description of some parameters
101-
- build type: `CMAKE_BUILD_TYPE=Release` (or `Debug`)
102-
- to build with modules from opencv_contrib set `OPENCV_EXTRA_MODULES_PATH` to `<path to
103-
opencv_contrib>/modules`
104-
- set `BUILD_DOCS=ON` for building documents (doxygen is required)
105-
- set `BUILD_EXAMPLES=ON` to build all examples
113+
- build type: `-DCMAKE_BUILD_TYPE=Release` (or `Debug`).
114+
- include Extra Modules: If you cloned the `opencv_contrib` repository and want to include its modules, set:
115+
116+
@code{.bash}
117+
-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
118+
@endcode
119+
- set `-DBUILD_DOCS=ON` for building documents (doxygen is required)
120+
- set `-DBUILD_EXAMPLES=ON` to build all examples
106121

107122
-# [optional] Building python. Set the following python parameters:
108-
- `PYTHON3_EXECUTABLE = <path to python>`
109-
- `PYTHON3_INCLUDE_DIR = /usr/include/python<version>`
110-
- `PYTHON3_NUMPY_INCLUDE_DIRS =
111-
/usr/lib/python<version>/dist-packages/numpy/core/include/`
123+
- `-DPYTHON3_EXECUTABLE=$(which python3)`
124+
- `-DPYTHON3_INCLUDE_DIR=$(python3 -c "from sysconfig import get_paths as gp; print(gp()['include'])")`
125+
- `-DPYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c "import numpy; print(numpy.get_include())")`
112126
@note
113-
To specify Python2 versions, you can replace `PYTHON3_` with `PYTHON2_` in the above parameters.
127+
Python 2 has reached its end of life. It is recommended to use Python 3 for building Python bindings.
114128

115129
-# Build. From build directory execute *make*, it is recommended to do this in several threads
116130

117-
For example
131+
For example:
132+
133+
@code{.bash}
134+
make -j$(sysctl -n hw.ncpu) # runs the build using all available CPU cores
135+
@endcode
136+
137+
-# After building, you can install OpenCV system-wide using:
138+
139+
@code{.bash}
140+
sudo make install
141+
@endcode
142+
143+
-# To use OpenCV in your CMake-based projects through `find_package(OpenCV)`, specify the `OpenCV_DIR` variable pointing to the build or install directory.
144+
145+
For example:
146+
147+
@code{.bash}
148+
cmake -DOpenCV_DIR=~/build_opencv ..
149+
@endcode
150+
151+
### Verifying the OpenCV Installation
152+
153+
After building (and optionally installing) OpenCV, you can verify the installation by checking the version using Python:
154+
118155
@code{.bash}
119-
make -j7 # runs 7 jobs in parallel
156+
python3 -c "import cv2; print(cv2.__version__)"
120157
@endcode
121158

122-
-# To use OpenCV in your CMake-based projects through `find_package(OpenCV)` specify `OpenCV_DIR=<path_to_build_or_install_directory>` variable.
159+
This command should output the version of OpenCV you have installed.
123160

124161
@note
125162
You can also use a package manager like [Homebrew](https://brew.sh/)
126163
or [pip](https://pip.pypa.io/en/stable/) to install releases of OpenCV only (Not the cutting edge).
164+
165+
- Installing via Homebrew:
166+
167+
For example:
168+
169+
@code{.bash}
170+
brew install opencv
171+
@endcode
172+
173+
- Installing via pip:
174+
175+
For example:
176+
177+
@code{.bash}
178+
pip install opencv-python
179+
@endcode
180+
181+
@note To access the extra modules from `opencv_contrib`, install the `opencv-contrib-python` package using `pip install opencv-contrib-python`.

0 commit comments

Comments
 (0)