-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Closed
Description
System information (version)
- OpenCV => commit Objc binding #17165
- Operating System / Platform => iOS Swift
- Compiler => Xcode Version 11.5 (11E608c)
$ swift --version
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.5.0
$ cmake --version
cmake version 3.17.3
$ python --version
Python 2.7.18
$ xcode-select --version
xcode-select version 2373.
Detailed description
OpenCV's Objective-C / Swift support is very awesome!
Thanks to @komakai @alalek @vpisarev .
Now, I'm trying to create a Mat from a UIImage in an iOS App project by Swift.
let srcMat = Mat(uiImage: srcImage)
Then, the -[Mat initWithUIImage:]: unrecognized selector sent to instance error occurs in this line.
Steps to reproduce
$ git clone https://github.com/opencv/opencv.git- Run
$ opencv/platforms/ios/build_framework.py <outputdir> - Create an iOS project, add
opencv2.framework&libc++.tbdin the project - Write the code
ViewController.swift
import UIKit
import opencv2
class ViewController: UIViewController {
@IBOutlet weak var srcImageView: UIImageView!
@IBOutlet weak var dstImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(named: "サンプル画像")!
self.srcImageView.image = image
self.dstImageView.image = self.convertColor(source: image)
}
func convertColor(source srcImage: UIImage) -> UIImage {
let srcMat = Mat(uiImage: srcImage) // ERROR!
let dstMat = Mat()
Imgproc.cvtColor(src: srcMat, dst: dstMat, code: .COLOR_RGB2GRAY)
return dstMat.toUIImage()
}
}
-[Mat initWithUIImage:]: unrecognized selector sent to instance 0x280554620
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Mat initWithUIImage:]: unrecognized selector sent to instance 0x280554620'
*** First throw call stack:
(0x1b03e4300 // ... // 0x1b01d52dc)
libc++abi.dylib: terminating with uncaught exception of type NSException
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
answers.opencv.org, Stack Overflow, etc and have not found solution - I updated to latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc
Reactions are currently unavailable