I am working on an OpenCV project where I am taking input from iPhone native camera as CMSampleBuffer
now I wanted to create Mat instance that is required in OpenCV for further process
I have found some old post related with it but all are not working in current swift as those are pretty old.
2
Answers
As far as I know openCV is written in C++ and you will have to interact with it using an Objc++ or an Objc wrapper.
Hence the resources you found are solid and there are many others on working with OpenCV on iOS. A simple swifty wrapper I found online is – https://github.com/Legoless/LegoCV.
There is a full interoperability between Objc/Objc++ and swift and it is fairly easy to implement. See these two resources for more info – https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_objective-c_into_swift
https://rderik.com/blog/understanding-objective-c-and-swift-interoperability/
First, convert CMSampleBuffer To UIImage.
Then you can easily convert UIImage to Mat and return UIImage with/without doing something.
OpenCVWrapper.h file
OpenCVWrapper.mm file