[OpenCV] building of openCV on Mac platform (Xcode + openCV 2.4.10) and opencvxcode

Source: Internet
Author: User
Tags install brew

[OpenCV] building of openCV on Mac platform (Xcode + openCV 2.4.10) and opencvxcode
1. Preface

From today on, we started to use Mac to run openCV. At first, I felt that the development resistance was not too great. In fact, it was more complicated than Windows. The current time point is configured

  • OS x yosemite 10.10.3
  • OpenCV 2.4.10(The latest version is 3.0 RC1)
  • Xcode Version 6.3.2 (6D2105)

In this configuration, I set up my openCV platform according to the following steps.

2. Configure the environment Step 2.1 openCV Selection

As mentioned earlier, the latest version of openCV is openCV 3.0 RC1. I chose to use openCV 3.0 RC1 at the beginning. However, after the configuration, the program compilation failed, and it seems that a header file could not be found. I also forgot it at the time. I will try to update it after 3.0 RC1 is updated. If there is still a problem at that time, I will try again.

  • OpenCV download link: http://opencv.org/downloads.html
2.2 preparations for installing openCV
  • Install brew

    This software is powerful and is the management tool of the next suite on the Mac platform. You can run a command to install and uninstall a suite. Its official website (http://brew.sh/index_zh-cn.html) to write the way to start.

    In the terminal window, enter the following script

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  • Install CMake

    CMake is a cross-platform compilation tool, which is also a required tool. Because Homebrew is installed, you can enter the following command in the terminal to install CMake.

    sudo brew install cmake

Permissions are required here.

  • IDE Selection: Xcode Installation

    In fact, there are many options here. I chose to use Apple's Xcode to run openCV. It's quite simple here, just download it.

2.3 openCV Installation

Start to install openCV. First, extract the downloaded zip file and put it in a specific path. Terminal, run the cd command to enter the path. Then run the following code:

  cd <path-opencv>  mkdir release  cd release  cmake -G "Unix Makefiles" ..  make 

Follow these steps to install openCV. There is a problem here. When I use openCV 2.4.10 for installation, there will be two errors.

error: comparison of array 'this->latestPoints' not equal to a null pointer is always true  [-Werror,-Wtautological-pointer-compare]if (latestPoints != NULL)error: address of array 'this->latestCounts' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]if( latestCounts )    

These two errors come fromCalibfilter. cppThis file, you need to modify part of the code, and then you can install it. For details, refer to this blog.

Problems and Solutions for installing OpenCV2.4.10 on MacOS10.10

Follow the link below to modify the code in the specified places, and then you can install openCV 2.4.10.

  • In the path/usr/local/includeThe opencv and opencv2 subfolders are generated, which contain many opencv header files.
  • In the path/usr/local/libThe related libraries of opencv are also generated.
2.4 uninstall openCV

It's easy to uninstall. Go back to the release directory and execute the command.sudo make uninstallThat's all right. Then, you need to clear it manually./usr/local/Some related files about opencv in this directory.

3. Create an openCV project under Xcode
  • First, open the prepared Xcode and select OS X-> Application-> Command Line Tool in the following interface.

  • Enter the name of your product and select the Language C ++.

  • You must specify the Header search path for the new project. Enter/usr/local/includeAnd/usr/local/include/opencvYou can.

  • You must specify the Library search path for the new project. Enter/usr/local/lib

  • Check whether the C ++ standard library is libstdc ++.

  • Finally, add the required. dylib file for the project. Create a new folder openCV_Frameworks under the project, right-click and choose Add Files ..

    Go to path/usr/local/libFind the. dylib file required by the program. For convenience, I add all. dylib files to the project.

  • So far, Xcode can be used in mac to develop openCV. The code for the test is as follows: Read the image from the Mac camera, and then the edge is extracted and then displayed by the canny command.

//// Main. cpp // Camera_Capture /// Created by zhoufan on 15/5/24. // Copyright (c) 2015 zhoufan. all rights reserved. // # include <iostream> # include <opencv2/core. hpp> # include <opencv2/highgui. hpp> # include <opencv2/opencv. hpp> using namespace std; using namespace cv; IplImage * Dokan (IplImage * image_input, double lowThresh, double highThresh, double aperture) {if (image_input-> nChannels! = 1) return (0); IplImage * image_output = cvCreateImage (cvGetSize (image_input), image_input-> depth, image_input-> nChannels); cvkan (image_input, image_output, lowThresh, highThresh, aperture); return (image_output);} int main (int argc, char * argv []) {cvNamedWindow ("Camera", CV_WINDOW_AUTOSIZE); CvCapture * capture = cvCreateCameraCapture (CV_CAP_ANY ); assert (capture! = NULL); IplImage * frame = 0; frame = cvQueryFrame (capture); IplImage * frame_edge = cvCreateImage (cvGetSize (frame), IPL_DEPTH_8U, 1); while (1) {frame = cvQueryFrame (capture); if (! Frame) break; cvConvertImage (frame, frame_edge, 0); frame = cvCloneImage (frame_edge); frame_edge = Dokan (frame_edge, 70, 90, 3); cvShowImage ("Camera", frame_edge ); char c = cvWaitKey (15); if (c = 27) break;} cvReleaseCapture (& capture); cvReleaseImage (& frame_edge); cvReleaseImage (& frame); return (int) 0 ;}

Shows the execution result.

4. Statement

Now, you can have fun playing with openCV in Xcode. In fact, when installing openCV 2.4.10, there will still be some warnings. Maybe there will be some problems in future development. Well, let's talk about it later.

Published in blog: http://blog.csdn.net/thnh169/

References

[1] Develop With OpenCV on Mac: http://hujiaweibujidao.github.io/blog/2014/03/13/develop-with-opencv-on-mac-os-x/
OpenCV 2.4.6 + mac Xcode 4.6 Tutorial: http://vincecc.blogspot.jp/2013/09/opencv-246-mac-xcode-46.html
[3] installing OpenCV2.4.10 on MacOS10.10 Problems and Solutions: http://blog.sina.com.cn/s/blog_6a740b360102ve3s.html
[4] OpenCV on Mac OSX: A step-by-step guide: http://tilomitra.com/opencv-on-mac-osx/
[5] Using OpenCV: http://blog.devtang.com/blog/2012/10/27/use-opencv-in-ios/ in MacOS and iOS Systems

============== Update log ===================================

2015-5-25 First Edition

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.