Quick Start
Get OpenCV running on iOS in minutes:Build Framework
This builds for iOS devices (arm64) and simulators (x86_64, arm64). Takes 15-30 minutes.
System Requirements
- macOS: 10.15 (Catalina) or later
- Xcode: 12.2 or later
- CMake: 3.19.0 or later (3.17+ for older Xcode)
- Python: 3.6 or later
- iOS Deployment Target: 9.0 or later (default)
Supported Architectures
OpenCV iOS framework includes:| Platform | Architectures | Usage |
|---|---|---|
| iOS Device | arm64, armv7, armv7s | Physical iPhones and iPads |
| iOS Simulator | x86_64, arm64 | Testing on Mac (Intel and Apple Silicon) |
By default,
build_framework.py builds for arm64 (devices) and x86_64 + arm64 (simulators). Older armv7/armv7s can be included if needed.Building OpenCV Framework
Standard Build
The simplest way to build OpenCV for iOS:~/ios/opencv2.framework
Build with opencv_contrib Modules
Include extra modules:Custom Build Options
- Specify Output Directory
- Exclude Modules
- Specific Architectures
- Dynamic Framework
Complete Build Command
Build Script Options
Key options forbuild_framework.py:
Building for Specific iOS Versions
Set minimum deployment target:Building visionOS Framework
For Apple Vision Pro:Framework Structure
The built framework contains:Integrating into Xcode Projects
Method 1: Drag and Drop (Quick)
Add Framework
- Drag
opencv2.frameworkinto your Xcode project - Check “Copy items if needed”
- Select your target
Link Framework
Ensure framework is in Target → General → Frameworks, Libraries, and Embedded ContentSet to “Embed & Sign” for dynamic frameworks or “Do Not Embed” for static.
Method 2: CocoaPods
For released versions:Method 3: Swift Package Manager
For projects using SPM:- File → Add Packages
- Enter OpenCV repository URL
- Select version
Official SPM support may be limited. Check OpenCV repository for latest status.
Using OpenCV in Code
Objective-C
Simple usage:Objective-C++ Bridge for Swift
Create a wrapper class:Swift
Use through Objective-C++ wrapper:Advanced Objective-C++ Integration
Direct Mat usage in .mm files:Camera Integration
Real-time camera processing:Core Image Integration
Convert between OpenCV Mat and CIImage:Performance Optimization
Use Accelerate Framework
OpenCV automatically uses iOS’s Accelerate framework for optimized BLAS/LAPACK operations.Enable NEON Instructions
Built by default for ARM architectures:Multi-threading
Troubleshooting
Build fails with CMake version error
Build fails with CMake version error
Update CMake:Xcode 12.2+ requires CMake 3.19.0 or later.
Undefined symbols for architecture
Undefined symbols for architecture
- Ensure all required system frameworks are linked
- Check framework was built for correct architecture
- Verify bitcode settings match between app and framework
File not found: opencv2/opencv.hpp
File not found: opencv2/opencv.hpp
- Ensure framework is added to project
- Check Build Settings → Framework Search Paths
- Verify Header Search Paths includes framework
Swift cannot find OpenCVWrapper
Swift cannot find OpenCVWrapper
- Ensure .mm file is in your target
- Add bridging header if needed:
- Set in Build Settings → Objective-C Bridging Header
Sample Applications
Explore example apps in the OpenCV repository:- HelloWorld - Basic OpenCV integration
- FaceDetection - Real-time face detection
- VideoFilters - Video processing effects
- SquareDetection - Shape detection
App Store Submission
Privacy Permissions
Add toInfo.plist:
Bitcode
If using dynamic framework, ensure bitcode settings match:Framework Size Optimization
Next Steps
Swift Integration
Advanced Swift usage patterns
Camera Processing
Real-time camera applications
Core ML Integration
Combine OpenCV with Core ML
Sample Apps
Explore example projects
