[OpenCV] OpenCV under Mac Platform (Xcode + OpenCV 2.4.10)

Source: Internet
Author: User

1. Preamble

Starting today, start using your Mac to run OPENCV. Start feeling should actually develop resistance is not too big look, actually speaking, actually is more cumbersome than Windows. The current point configuration is

    • OS X Yosemite 10.10.3
    • OpenCV 2.4.10 (The current point of the latest version is: 3.0 RC1)
    • Xcode Version 6.3.2 (6d2105)

In this configuration, I set up my OpenCV platform in the following steps.

2. Steps to configure the Environment 2.1 OPENCV selection

Just now, the latest version of Point OpenCV is OpenCV 3.0 RC1. I also chose to use the OPENCV 3.0 RC1 in the beginning, however, after the configuration, the program compiles cannot pass, there is a header file seems to be unable to find. At that time also forgot, follow-up 3.0 RC1 Update, I try to update it, then there is still a problem, I put it up again.

    • OpenCV Download Link: http://opencv.org/downloads.html
2.2 Pre-preparation for installation of OPENCV
    • Installing Brew

      This software is very powerful, is the next suite of Mac platform management tools. You can use a command to install a suite with uninstall. Its official website (http://brew.sh/index_zh-cn.html) wrote the way to start.

      In the terminal window, enter the following script

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

    • Installing CMake

      CMake is a cross-platform compilation tool, which is also a necessary tool. Since we have installed the homebrew, we can enter the following command in the terminal to install CMake.

    sudo brew install cmake

Permissions are required here.

    • IDE Selection: Installation of Xcode

      In fact there are a lot of options, I chose to use the apple comes with Xcode to run OPENCV. It's quite simple here, just download it.

Installation of 2.3 OpenCV

Starting from here to install the OPENCV, first unzip the downloaded zip file and put it under a specific path. In the terminal, enter the path through the command CD. Then execute the following code

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

Follow the above steps to install the OPENCV. There is a problem here, when I use the OpenCV 2.4.10 installation, there is a place to jump two error.

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 error is from calibfilter.cpp This file, you need to modify the part of the code inside, it can be installed. Specific can refer to this blog, said very detailed.

Problems and workarounds for installing OpenCV2.4.10 in MacOS10.10

Following this link, after modifying the code in a few places, you can install the OpenCV 2.4.10.

    • The OpenCV /usr/local/include and Opencv2 subfolders are generated under the path, which contains many OpenCV header files.
    • The associated /usr/local/lib libraries for OPENCV are also generated under the path.
Uninstall of 2.4 OpenCV

Uninstall is also very simple, back to the release directory, the execution sudo make uninstall of the command is duly completed. Then, you need to manually /usr/local/ clean up some of the relevant files about OPENCV in this directory.

3. Create a OPENCV project under Xcode
    • First open the pre-prepared Xcode, and select the Command line Tool, application, Os X, in one of the following interfaces

    • Fill in the name of your product, and then select the language as C + +.

    • You need to specify a header search path for the new project. Here, fill it /usr/local/include in /usr/local/include/opencv with it.

    • You need to specify a library search path for the new project. Here, fill in/usr/local/lib

    • In fact, it is necessary to check whether the C + + standard library is libstdc++.

    • Finally, add the required. dylib file for the project. Create a new folder under Project Opencv_frameworks, right-click Add Files to.

      Go to the /usr/local/lib path to find the. dylib file that the program must have, for convenience, I add all the. dylib files to the project.

    • So far, using Xcode on your Mac can be a OPENCV development. The test uses the code shown below to read the image from the camera that comes with the Mac, and then canny extracts the edge and then displays it.

////Main.cpp//Camera_capture////Created by Zhoufan on 15/5/24.//Copyright (c) 2015 Zhoufan. All rights reserved.//#include <iostream>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/opencv.hpp>using namespace STD;using namespacecv;iplimage* Docanny (iplimage* image_input,DoubleLowthresh,DoubleHighthresh,DoubleAperture) {if(Image_input->nchannels! =1)return(0); iplimage* image_output = Cvcreateimage (Cvgetsize (image_input), image_input->d    Epth, Image_input->nchannels); Cvcanny (image_input,image_output,lowthresh,highthresh,aperture);return(Image_output);}intMainintargcChar* 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 = Docanny (Frame_edge, -, -,3); Cvshowimage ("Camera", Frame_edge);Charc = Cvwaitkey ( the);if(c = = -) Break;    } cvreleasecapture (&capture);    Cvreleaseimage (&frame_edge); Cvreleaseimage (&frame);return(int)0;}

The execution results are as shown.

4. Statements

To this, already can under Xcode happily and OpenCV June play. Actually want to say is, in the installation OpenCV 2.4.10, still will pop some warring, perhaps in later development, will have some problems. Well, I'll talk about it.

Originally Posted in Blog: http://blog.csdn.net/thnh169/

Reference documents

[1] Develop with OpenCV on mac:http://hujiaweibujidao.github.io/blog/2014/03/13/develop-with-opencv-on-mac-os-x/
[2] OpenCV 2.4.6 + Mac Xcode 4.6 installation teachings: http://vincecc.blogspot.jp/2013/09/opencv-246-mac-xcode-46.html
[3] problems and solutions encountered in MacOS10.10 installation OpenCV2.4.10: 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

[OpenCV] OpenCV under Mac Platform (Xcode + OpenCV 2.4.10)

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.