mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
7cc6d8576c
Use Xcode DocC tool for buiding Apple platform docs + add quick-start tutorial #28704 ### Pull Request Readiness Checklist - [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 - [x] There is a reference to the original bug report and related work This PR resolves https://github.com/opencv/opencv/issues/28702 and https://github.com/opencv/opencv/issues/28703 Additionally it resolves build issues on Apple platforms by making build scripts run with Python 3
2.4 KiB
2.4 KiB
This is the documentation for the iOS OpenCV framework.
Quick Start Tutorial
Follow the steps below to get a simple "Hello World" app running on iOS
- Open Xcode and create a new project from the File > New > Project... menu
- From template selection dialog select the
iOStab and then selectApp
- Enter a name for the project and set Interface to Storyboard and Language to Swift
- Choose a location to save the project
- Create a new folder
Framework
- In a Finder window copy the framework file to the newly created folder. The framework should appear in the project navigator as below. (Note: in this case the framework has extension
.frameworkbut depending on how you built it or from where you obtained it your framework may have extension.xcframework)
- In the project navigator select the
ViewController.swiftfile
- Add an
importfor the OpenCV framework below the existing import forUIKit
import opencv2
- Replace the implementation of the
viewDidLoadfunction with the following code
override func viewDidLoad() {
super.viewDidLoad()
let white = Scalar(255, 255, 255, 255)
let black = Scalar(0, 0, 0, 255)
let m = Mat(rows: 400, cols: Int32(view.frame.width), type: CvType.CV_8UC4, scalar: white)
Imgproc.putText(img: m, text: "Hello World", org: Point(x: 10, y: 150), fontFace: HersheyFonts.FONT_HERSHEY_DUPLEX, fontScale: 2, color: black)
let image = m.toUIImage()
let imageView = UIImageView(image: image)
self.view.addSubview(imageView)
}
- The
ViewController.swiftfile should now look like this
- Launch the app
- The app home screen should look like this
If that has all worked well then congratulations. If not then feel free to reach out to the OpenCV community for help. Also feel free to contribute fixes and improvements.









