OpenCV For iOS 1: & #160; Connect to OpenCV 3.0, iosopencv

Source: Internet
Author: User
Tags visual studio 2010

OpenCV For iOS 1: connect to OpenCV 3.0, iosopencv

For more information about this article, see Instant OpenCV for iOS with the latest development platform.


The Development Environment used in this series of articles is:

1) Xcode 6

2) OpenCV for iOS 3.0.0 alpha


Next, Step by Step describes how to use OpenCV on the latest platform. This example uses converting a color image into an edge image.


Step 1: Create a new project

Step 2: Add opencv2.framework to Building phase


Step 3: Because openCV uses C ++, to run c ++ code in the project, you need to change the file name suffix from. m to. mm, as shown in

Step 4: import the OpenCV file in ViewController. mm

# Import <opencv2/opencv. hpp>

# Import <opencv2/imgproc/types_c.h>

# Import <opencv2/imgcodecs/ios. h>

Because opencv. hpp does not contain opencv2 files, you need to import them separately.

Step 5: Enter the following code:

@interface ViewController (){    cv::Mat cvImage;}@property (weak, nonatomic) IBOutlet UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    CGRect rect = [UIScreen mainScreen].bounds;    self.imageView.frame = rect;        UIImage *image = [UIImage imageNamed:@"road.JPG"];    // Convert UIImage * to cv::Mat    UIImageToMat(image, cvImage);    if (!cvImage.empty()) {        cv::Mat gray;        // Convert the image to grayscale;        cv::cvtColor(cvImage, gray, CV_RGBA2GRAY);        // Apply Gaussian filter to remove small edges        cv::GaussianBlur(gray, gray, cv::Size(5,5), 1.2,1.2);        // Calculate edges with Canny        cv::Mat edges;        cv::Canny(gray, edges, 0, 60);        // Fill image with white color        cvImage.setTo(cv::Scalar::all(255));        // Change color on edges        cvImage.setTo(cv::Scalar(0,128,255,255),edges);        // Convert cv::Mat to UIImage* and show the resulting image        self.imageView.image = MatToUIImage(cvImage);    }        }

The intermediate process is not considered. The key point is to use two functions to convert the UIImage in iOS and the cv: Mat format in openCV, so as to achieve effective connection between iOS and OpenCV.

The test results are as follows:


We can see from the above that we can use OpenCV in iOS very easily. The next step is to understand and use the functions and algorithms of OpenCV.




Opencv243 just compiled, but there is only one opencvhpp file under/include/opencv2. Is there any other header file?

Include directory:
E: \ opencv \ build \ include
E: \ opencv \ build \ include \ opencv
E: \ opencv \ build \ include \ opencv2
Library directory:
E: \ opencv \ build \ x86 \ vc10 \ lib

Dependency additional item Debug:
Opencv_core243d.lib
Opencv_highgui243d.lib
Opencv_video243d.lib
Opencv_ml243d.lib
Opencv_legacy243d.lib
Opencv_imgproc243d.lib
Opencv_flann243d.lib
Opencv_features2d243d.lib
Opencv_calib3d243d.lib
Opencv_objdetect243d.lib
Opencv_contrib243d.lib

Release:
Opencv_core243.lib
Opencv_highgui243.lib
Opencv_video243.lib
Opencv_ml243.lib
Opencv_legacy243.lib
Opencv_imgproc243.lib
Opencv_flann243.lib
Opencv_features2d243.lib
Opencv_calib3d243.lib
Opencv_objdetect243.lib
Opencv_contrib243.lib

// Modify the path.
// Remember to modify system environment variables

Configure OpenCV in vs2010

Key steps for configuration under Visual Studio 2010 + Opencv2.3
Opencv download OpenCV for Windows, superpack version
Address: www.opencv.org.cn/..ck.exe
The following content is in the build folder.
1. Set environment variables:
My computer ---> right-click ---> properties ---> advanced ---> environment variable ---> in user variables, create two items: path and OPENCV
Step 1: Add I: \ Program Files \ OpenCV2.3 \ build \ x86 \ vc10 \ bin to the path to add the dll file
Step 2: add the OPENCV environment variable I: \ Program Files \ OpenCV2.3 \ build

2. Open an Opencv project and click "View" in the menu directory ---> Property Manager ---> double-click the project name
Step 3: add
I: \ Program Files \ OpenCV2.3 \ build \ include
I: \ Program Files \ OpenCV2.3 \ build \ include \ opencv
I: \ Program Files \ OpenCV2.3 \ build \ include \ opencv2

Step 4: add
I: \ Program Files \ OpenCV2.3 \ build \ x86 \ vc10 \ lib

Step 5 add the lib library file and add

Opencv_core230d.lib
Opencv_highgui230d.lib
Opencv_video230d.lib
Opencv_ml230d.lib
Opencv_legacy230d.lib
Opencv_imgproc230d.lib

Step 6: add
Opencv_core230.lib
Opencv_highgui230.lib
Opencv_video230.lib
Opencv_ml230.lib
Opencv_legacy230.lib
Opencv_imgproc230.lib

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.