OpenCV 4.11.0-pre
Open Source Computer Vision
|
Prev Tutorial: Use OpenCL in Android camera preview based CV application
Next Tutorial: Cross compilation for ARM based Linux systems
Original author | @sajarindider |
Compatibility | OpenCV >= 3.4 |
The following steps have been tested for macOS (Mavericks) but should work with other versions as well.
This tutorial will assume you have Python, NumPy and Git installed on your machine.
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.
.dmg
package and launch it from Applications. That will give you the UI app of CMake/usr/local/bin/
by default. Complete the installation by choosing Install command line links.Test that CMake is installed correctly by running:
@code{.bash} brew install cmake @endcode
You can use the latest stable OpenCV version or you can grab the latest snapshot from our Git repository.
Launch Git client and clone OpenCV repository. If you need modules from OpenCV contrib repository then clone it as well.
For example:
@code{.bash} cd ~/<your_working_directory> git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git @endcode
Create a temporary directory, which we denote as build_opencv
, where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there.
For example:
Configuring. Run cmake [<some optional parameters>] <path to the OpenCV source directory>
For example:
Alternatively, you can use the CMake GUI (cmake-gui
):
/Users/your_username/opencv
/Users/your_username/build_opencv
-DCMAKE_BUILD_TYPE=Release
(or Debug
).include Extra Modules: If you cloned the opencv_contrib
repository and want to include its modules, set:
-DBUILD_DOCS=ON
for building documents (doxygen is required)-DBUILD_EXAMPLES=ON
to build all examples-DPYTHON3_EXECUTABLE=$(which python3)
Build. From build directory execute make, it is recommended to do this in several threads
For example:
After building, you can install OpenCV system-wide using:
To use OpenCV in your CMake-based projects through find_package(OpenCV)
, specify the OpenCV_DIR
variable pointing to the build or install directory.
For example:
After building (and optionally installing) OpenCV, you can verify the installation by checking the version using Python:
@code{.bash} python3 -c "import cv2; print(cv2.__version__)" @endcode
This command should output the version of OpenCV you have installed.
Installing via Homebrew:
For example:
Installing via pip:
For example:
opencv_contrib
, install the opencv-contrib-python
package using pip install opencv-contrib-python
.