Preface:
The development of IOS7 has been in January. Recently in preparation for the research, a little want to go to the CV direction development. So I started learning OpenCV.
It's been a long time watching csdn. Also from the very Dogbo master that learned a lot of knowledge, so I also from this week to open their own blog tour, from the beginning of zero to learn OpenCV, from scratch to write a blog. haha ~
All right. Don't say much nonsense. Go to the chase.
。
use OpenCV under IOS7
For MAC OS to use OPENCV of course to compile, but assuming that only the use of OpenCV under iOS, only need to import bulid good opencv2.framework into project can.
Opencv2.framework can be downloaded on the OPENCV official website. Portal :opencv2.framework
Below we create a new single View appliction under Xcode, named Cvforios.
Copy the downloaded opencv2.framework to the new project folder, and then import it into the project folder under Frameworks, and Libc++.dylib under IOS7.1, as well.
You then need to set the C + + standard Library to libstdc++ in build settings.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2hhd25fahq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "width=" 614 "height=" >
Because the Min macro in OpenCV has a conflict with the Min macro of Uikit. Therefore, in the. pch file, first define the OPENCV header file. Otherwise there will be a compilation error.
Find cvforios-preix.pch changes such as the following:
at this point, the previous configuration work has been completed.
First case: box filtering of photos on your phone with OpenCV
Because iOS generally uses the UIImage type to store the display image, to manipulate the image with OpenCV, you need to be able to freely convert between Cv::mat and UIImage.
Here we use the Open source code on GitHub. Portal :Aptogo
The code is as follows:
Note: the. mm file is a description of the mixed use of object-c and C + + two programming languages in this file, because OpenCV uses C + +, so be aware that only the OpenCV file must be replaced with the suffix. mm
Well, then we finally get to the point, first Add a button, a Uiimageview control, a uislider on the Main.storyboard. Layouts such as the following:
The message responses and connections for each control are as follows:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2hhd25fahq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "align=" left "width=" "height=" 292 ">
change the suffix name of the view controller implementation file to. mm. Let Viewcontroller implement uiimagepickercontrollerdelegate and uiactionsheetdelegate protocols
Detailed implementation code such as the following:
Header file:
implementation file:
Call Cv::boxfilter to implement the box filter, you can adjust the size of the form through the slider bar. Finally effects such as the following:
Doge after the box filter or so with sense, hazy eyes, haha!
Finally, the preparation of the work is done, and then you can use OPENCV on the phone to play ~
in the future, many other more interesting functions will be implemented with OPENCV on IOS7. Finally the entire case code is attached:Cvforios
(reprint please indicate author and source: Shawn-ht http://blog.csdn.net/shawn_ht do not use for commercial purposes without consent)
Article: http://blog.devtang.com/blog/2012/10/27/use-opencv-in-ios/
OpenCV Development from a zero-learning OpenCV IOS7 (xcode5.1.1&opencv2.49)