Install OpenCV2.4.10 whole process on Mac OSX10.10 (including Homwbrew,cmake installation, configure OpenCV2.4.10 on XCode6.1.1)

Source: Internet
Author: User
Tags install homebrew

First of all, the installation environment Mac OSX10.10, the installation version of Opencv2.4.10,xcode version 6.1.1, is basically the latest version of each software. Because OpenCV3.0 is still in beta, the official version is not released, so it's useless. 3.0. The installation steps are described in detail below:

One, install homebrewhomebrew is similar to Ubuntu's Apt-get,fedora yum, simply for the convenience of installing software. Open the Homebrew official website http://brew.sh/index_zh-cn.html and find the ruby command to install homebrew: ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"


Two, install CMake with homebrewEnter brew Update, and then enter brew upgrade. After that, enter the brew install CMake so that you can wait a few cmake to install it.
third, to OPENCV official website Download mac/linux version of the OpenCVAddress: http://opencv.org/downloads.html Because the latest 3.0 is the beta version, Zajia This choice is 2.4.10, the download process found that the Mac seems to be on the SourceForge link dead and alive can not open. Later on the PC speed brush on the next good. Inconvenient to go to windows up and down can change a browser on Mac, this article will also attach 2.4.10 version of the Mac/linux download link.


the file name after download is Opencv-2.4.10.zip, and the size is 91.7M. Double-click Unzip, go to the /users/yanzi/desktop/Project/opencv-2.4.10/Path, then create a new release folder, and then go to the release folder. Enter cmake-g "Unix makefiles": or enter it on the official website .
Cmake-d cmake_build_type=release-d cmake_install_prefix=/usr/local.
is also possible. Then enter make to start compiling, and on the Mac the compilation speed is faster than on Windows. Compile for about 10 minutes, then enter sudo make install. at this point OpenCV is installed on Mac.
Four, configuring Xcode, writing test cases for OPENCVopen Xcode and create a new command line project:
project name Testopencvdemo, pay attention to language selection C + +.
so the C + + HelloWorld is built, the compilation should be able to run normally. The next step is to configure Xcode to write the code. Select the project on the left, then select targets on the right, then buildsettings the search box to the right, and you will soon be able to find the search paths settings. In the header search paths input:/usr/local/include in the Library search paths input:/usr/local/libas follows:



then find link Binary with Libraries in build phases, click on the + sign
Select Add other and press the/key to enter the path of the Lib/usr/local/lib, click Go:

then is the choice of OpenCV Library, with which to add which, no need to add the end. We add the most basic of several:



multiple selections can be achieved by pressing command. Add the above four most commonly used to be able to the test code of this time. Once added, you can see it on the left:

enter the following in the main.cpp to display a picture and display the grayscale:
  main.cpp//  testopencv////  Created by Yanzi on 14/12/22.//  Copyright (c) 2014 Yanzi. All rights reserved.//#include <iostream>using namespace std; #include <opencv2/opencv.hpp>using namespace Cv;int Main (int argc, const char * argv[]) {    //Insert code    here ... Std::cout << "Hello, world!\n";    String path = "/users/yanzi/documents/photo/nanhuaijin.jpg";    Mat image = Imread (path);    Namedwindow ("Nanhuaijin");    Imshow ("Nanhuaijin", image);        Mat Gray;    Cvtcolor (image, Gray, Color_rgba2gray);    Namedwindow ("Gray");    Imshow ("Gray", gray);    Waitkey (0);    return 0;}
The results of the operation are as follows:
at this point, add a little trick in the OpenCV use. Although Xcode is easy to use, it is sometimes unsatisfactory. As

Cvtcolor (image, Gray,) the third parameter it will not be complete, if you remember this parameter is a color at the beginning, then congratulations, Xcode can still fill the whole:


If you do not know, and do not want to ask the Niang, you can go to the OPENCV installation process in the decompression package,

/users/yanzi/desktop/Project/opencv-2.4.10 Path, input grep ' cvtcolor ' *-r this grep command in the second parameter * represents all files under the current path,-R means recursive search, You can see a bunch of things. (You can delete the release file at this time) and finally find

IMGPROC.HPP under the/opencv-2.4.10/modules/imgproc/include/opencv2/imgproc path of the/users/yanzi/desktop/project, Press Command+f to enter Cvtcolor to search,


This allows you to see a bunch of parameter descriptions of the function. Although more than the direct ask Niang trouble point, but programmers still want to cultivate this look at the source to solve the problem of the ability. Just a little.

Linux/mac version with OpenCV2.4.10: Http://pan.baidu.com/s/1eQ1pkkE
reference:http://wuzhaoxi1992511.blog.163.com/blog/static/18375811820132213544889/

Install OpenCV2.4.10 whole process on Mac OSX10.10 (including Homwbrew,cmake installation, configure OpenCV2.4.10 on XCode6.1.1)

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.