OS X 10.10 Environment installs OPENCV 2 and 3 simultaneously via homebrew

Source: Internet
Author: User

<!doctype html>

OS X 10.10 Environment installs OPENCV 2 and 3 simultaneously via homebrew

The OS X 10.10 environment is installed by homebrew simultaneously OPENCV 2 and 3 described above
我在Mac上配置OpenCV花费过很长时间,使用Win平台的同学大多数会给VS安装OpenCV库,在尝试过使用Xcode配置并建立OpenCV工程后,由于对Xcode环境的陌生以及其本身对C++支持的不完善,边很快放弃了。下面,具体但不是精简地说下OS X 10.10 中使用OpenCV的两种方式。1、CMake + OpenCV + 文本编辑器2、CMake + CLion
Dependent environment

This article uses the environment : OS X 10.10.5 ( newest, this fall will launch 10.11 official version )

Xcode and command line Tools

Apple is using the clang compiler, but the MAC system itself doesn't have a compiler, and by the way Linux releases have compiler gcc, so we need to install Xcode so our Mac has a build environment. (BTW, one of the most recent xcodeghost events is because Xcode contains the clang compiler, which is then modified so that the compiled app has some backdoor)

    • Xcode can be downloaded and installed in the App Store (CLT does not come with installation )
    • Command line tools is installed in two ways:
    • 1. Enter the reference link in the terminal

        xcode-select --install
    • 2, the official website download installs the https://developer.apple.com/downloads/choiceCommand Line Tools OS X 10.10 for Xcode 7

Homebrew

After I re-installed the system, I deeply realized the importance of homebrew, the missing Package manager for Mac, and yes, I have re-installed the system for Mac. Official address-or direct terminal input command

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Installation Step installation cmake,terminal input
    brew update    brew install cmake

Make a habit of brew update before the brew installs other packages, and as a homebrew whether the installation is a successful test

Installing OPENCV 2 and 3,terminal inputs
    brew tap homebrew/science    //安装OpenCV 2    brew install opencv    //安装OpenCV 3    brew install opencv3

At this point, OPENCV installation work has been completed, the following introduction to establish OPENCV Engineering

OpenCV Tutorial New CMakeLists.txt
    cmake_minimum_required(VERSION 2.8)    //OpenCVTutorial是我的工程名,可以替换为你自己的    project( OpenCVTutorial )    //这里将会使用OpenCV 2,所以是OpenCV    find_package( OpenCV )    include_directories( ${OpenCV_INCLUDE_DIRS} )    //OpenCVTutorial是工程名,OpenCVTutorial.cpp是源文件    add_executable( OpenCVTutorial OpenCVTutorial.cpp )    //OpenCVTutorial是工程名    target_link_libraries( OpenCVTutorial ${OpenCV_LIBS} )
New OpenCVTutorial.cpp source file
    #include "opencv2/highgui/highgui.hpp"    #include "opencv2/imgproc/imgproc.hpp"    #include "opencv2/core/core.hpp"    using namespace cv;    int main(){        VideoCapture cap(0);        while (true){            Mat Webcam;            cap.read(Webcam);            imshow("Webcam", Webcam);        }        waitKey(1);    }
Put the above two source files in the same directory

Here in my ~/documents/opencvprojects/opencvtutorial as you know, ~ means your home home directory

    cd ~/Documents/OpenCVProjects/OpenCVTutorial
Start CMake and compile, terminal input
    cmake .    make
Compile successfully, run
    ./OpenCVTutorial

The above routines use the OpenCV 2 library, which shows the configuration of OpenCV 3 below

OpenCV 3 Separate description
使用OpenCV 3需要改变两样东西一个是库文件的链接另一个是CmakeLists
Disconnect OpenCV 2 library link, terminal input
    brew unlink opencv
Link to OpenCV 3 library file
    brew ln opencv3 --force
Change CnakeLists.txt

Put

    find_package( OpenCV )

Switch

    find_package( OpenCV 3 )

Save

Re-cmake and compiling

OS X 10.10 Environment installs OPENCV 2 and 3 simultaneously via homebrew

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.