Install OpenCV 2 and 3 simultaneously in the OS X 10.10 environment through Homebrew

Source: Internet
Author: User

Install OpenCV 2 and 3 simultaneously in the OS X 10.10 environment through Homebrew
Previously, it took a long time for me to configure OpenCV on Mac. Most people who use the Win platform will install the OpenCV library for VS. After trying to configure and build the OpenCV project using Xcode, due to the strangeness of the Xcode environment and the imperfect C ++ support, I quickly gave up. The following describes the two methods of using OpenCV iN OS X 10.10. 1. CMake + OpenCV + Text Editor 2. CMake + CLion depends on the environment in this article: OS X 10.10.5 (the latest version will be available in the official version 10.11 This autumn) xcode and Command Line ToolsApple use the Clang compiler. However, the Mac system does not have its own compiler. By the way, the Linux release is accompanied by the gcc compiler, therefore, we need to install Xcode to make our Mac have a compiling environment. (Btw, one of the most recent XcodeGhost events is that Xcode contains the Clang compiler and is modified to make the compiled App have some backdoors) xcode can be downloaded and installed in App Store again (CLT is not included). Command Line Tools can be installed in two ways: 1. In Terminal, enter the reference link xcode-select -- install2. Download and install https://developer.apple.com/downloads/select command Line Tools OS x 10.10 for Xcode 7 Homebrew. After I reinstall the system, I deeply realized Homebrew. the importance of a package manager missing from Mac, yes, I have reinstalled the Mac system. Visit the official website-or directly enter the command ruby-e "$ (curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Installation Steps to install CMake, terminal enter brew update brew install cmake to develop the habit of brew update before brew installs other packages, and check whether the installation of OpenCV 2 and 3 is successful as Homebrew, terminal input brew tap homebrew/science // install OpenCV 2 brew install opencv // install OpenCV 3 brew install opencv3 so far, the installation of OpenCV has been completed. Next we will introduce the establishment of the OpenCV project OpenCV tutorialnew cmakelists.txt Cmake_minimum_required (VERSION 2.8) // OpenCVTutorial is my project name. You can replace it with your own project (OpenCVTutorial) // OpenCV 2 will be used here, So OpenCV find_package (OpenCV) include_directories ($ {OpenCV_INCLUDE_DIRS}) // OpenCVTutorial is the project name, OpenCVTutorial. cpp is the source file add_executable (OpenCVTutorial. cpp) // OpenCVTutorial is the project name target_link_libraries (OpenCVTutorial $ {OpenCV_LIBS}) to create OpenCVTutorial. cpp source file # include "ope Ncv2/highgui. hpp "# include" opencv2/imgproc. hpp "# include" opencv2/core. hpp "using namespace cv; int main () {VideoCapture cap (0); while (true) {Mat Webcam; cap. read (Webcam); imshow ("Webcam", Webcam) ;}waitkey (1) ;}put the two source files in the same directory. Here I am ~ /Documents/OpenCVProjects/OpenCVTutorial as you know ,~ Indicates your Home directory cd ~ /Documents/OpenCVProjects/OpenCVTutorial start CMake and compilation, and Terminal input cmake. make is compiled successfully and runs. the examples above/OpenCVTutorial use the library of OpenCV 2, the following will demonstrate how to configure OpenCV 3 in OpenCV 3 separately. Using OpenCV 3 requires two things: the Library file link and the CmakeLists, the Library Link of OpenCV 2, terminal input brew unlink opencv link library file brew ln opencv3 --forcechange cnakelists.txt change find_package (OpenCV) to find_package (OpenCV 3) Save and re-compile

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.