Quick Start
Get OpenCV running on macOS in minutes:Install Xcode Command Line Tools
Xcode 12.2 or later is required. The full Xcode app is recommended but not strictly necessary for basic builds.
Install CMake
System Requirements
- macOS: 10.12 (Sierra) or later
- Xcode: 12.2 or later
- CMake: 3.19.0 or later (3.17+ for older Xcode)
- Python: 3.8 or later (for Python bindings)
Installation Methods
- Build from Source
- Homebrew
- pip (Python only)
For the latest features and custom configuration:
Building for Apple Silicon
OpenCV supports native Apple Silicon (M1/M2/M3) builds:Native ARM64 Build
Universal Binary (x86_64 + arm64)
Universal binaries work on both Intel and Apple Silicon Macs, but result in larger file sizes.
Architecture-Specific Optimizations
Building OpenCV Framework
For use in Xcode projects, build OpenCV as a framework:~/opencv_build/opencv2.framework- The framework~/opencv_build/build/- Intermediate build files
Framework Build Options
Building XCFramework
For multi-platform distribution (macOS + iOS + Catalyst):- macOS: x86_64, arm64
- iOS: arm64, armv7
- iOS Simulator: x86_64, arm64
- Mac Catalyst: x86_64, arm64
opencv2.xcframework can be used across all Apple platforms.
XCFramework Build Options
Dependencies and Optional Features
Core Dependencies
Optional Dependencies
Image I/O
Image I/O
Video I/O
Video I/O
GUI Support
GUI Support
macOS uses native Cocoa framework by default (no additional dependencies).For Qt-based GUI:
Parallel Processing
Parallel Processing
OpenCL Support
OpenCL Support
macOS includes OpenCL by default:
CMake Configuration Options
Standard Build
Python-Specific Configuration
Python 2 support has been removed from recent OpenCV versions. Use Python 3.8 or later.
Optimized Build for Apple Silicon
Building with opencv_contrib
Include extra modules from opencv_contrib:Installation Locations
Default Installation
Withsudo make install, files are placed in:
Custom Installation
Using OpenCV in Xcode Projects
With CMake (Recommended)
In yourCMakeLists.txt:
With OpenCV Framework
- Drag
opencv2.frameworkinto your Xcode project - Add to Target → Build Phases → Link Binary With Libraries
- Include in code:
Verification
Test your installation:- C++
- Python
- Framework
Create Compile and run:
test.cpp:Performance Optimization
Use Accelerate Framework
macOS’s Accelerate framework provides optimized BLAS/LAPACK:Enable Multi-threading
Troubleshooting
Python module not found after installation
Python module not found after installation
Check installation path:Add to PYTHONPATH if needed:
CMake version too old error
CMake version too old error
Update CMake:Xcode 12.2+ requires CMake 3.19.0+
Architecture mismatch errors
Architecture mismatch errors
Ensure consistent architecture:
Framework build fails
Framework build fails
Clean and retry:Check Xcode and CMake versions meet requirements.
Next Steps
iOS Development
Build OpenCV for iOS devices
Getting Started
Write your first OpenCV application
Python Bindings
Use OpenCV with Python on macOS
XCFramework Guide
Build for all Apple platforms
