OPENCV development Environment configuration under MAC (Terminal and Xcode)

Source: Internet
Author: User

Pro ID Available: http://www.jianshu.com/p/11959977589a

    • Mac OS X 10.1
    • Xcode 7.2 (7c68)
    • OpenCV 2.4.13

      Mac OS10.11

OpenCV for Linux/mac

After downloading OpenCV, the CD enters the specified directory and uses the unzip command to extract
Please install the Homebrew command in advance
First install the CMake tool and then the CD into the unpacked folder

$ brew install cmake$ mkdir release$ cd release$ cmake -G "Unix Makefiles" ..$ make$ sudo make install

If there is no accident, the OPENCV has been installed successfully. Where Lib files are stored in the "/usr/local/lib" folder, h files are stored in "/usr/local/include".

Terminal lowered with OPENCV

Enter the development working directory and create a new test file DisplayImage.cpp

$ vi DisplayImage.cpp

and insert the following code:

#Include<cv.h>#Includeusing namespace cv; int main ( int argc, char** argv) {Mat image; image = Imread (Argv[1], 1); if (argc! = 2 | |!image.data) { printf ( "No image data \ n"); return -1;} namedwindow ( "Display Image", image), Waitkey (0); return 0;}           

New profile CMakeLists.txt, which is used to claim the makefile file, is as follows:

project( DisplayImage )find_package( OpenCV REQUIRED )add_executable( DisplayImage DisplayImage )target_link_libraries( DisplayImage ${OpenCV_LIBS} )

Compilation of two files

cd  <DisplayImage_directory> //进入DisplayImage.cpp文件所在目录cmake .make

Run the compiled results (the Turin.jpg file is in the same directory as the DisplayImage)

./DisplayImage turin.jpg

See the target picture, beautiful lovely Turin is to say success ~ Of course this is only the first step, in addition to C + + code to learn to write makefile (CMake) file Oh

Xcode calls OpenCV Library

Create an empty command line project


Command_line

Select the appropriate name, then go to the main page and replace the main file with the following code:


Main.cpp
#Include<iostream>#Include<opencv2/opencv.hpp>#Include<opencv2/highgui/highgui.hpp>#Include<opencv/cvaux.hpp>#Include<fstream>UsingNamespaceStd#Define BYTE unsigned charIntMain(int argc,const char * argv[]) {// The directory of this place needs to be changed to its own iplimage* img = cvloadimage ( "/users/kingsley/desktop/turin.jpg", 1); //nslog (IMG); //create a window to display the image Cvnamedwindow (1); //show the image in the window cvshowimage (//wait for the user-to-hit a key Cvwaitkey (0); //delete the image and Window cvreleaseimage (&img); Cvdestroywindow (" picture "); return 0;}         

Add lib file: Right click on the project name, select "Add files to.", use the shortcut key "Command+shift+g" in the pop-up go to the folder box, enter:/usr/local/lib, choose all dylib files and add to the project.

Add Lib file lookup support: Double-click the project name file, go to the "Build Settings" tab, and enter "/usr/local/lib" in the "Library Search Paths" column (you can use the search function)


Add LIB Support

Add header file: Click on the project name file, go to the "Build Settings" tab and enter "/usr/local/include/usr/local/include/opencv" in the "header Search Paths" field:


Header Search Paths

OPENCV development Environment configuration under MAC (Terminal and Xcode)

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.