turn from: http://blog.sciencenet.cn/home.php? Collcc=3456986939&collcc=3456885714&mod=space&uid=702148&do=blog&quickforward=1&id= 657754%20%e5%9c%a8mac%e4%b8%8b%e4%bd%bf%e7%94%a8opencv%ef%bc%8c%20%e5%9c%a8xcode%e4%b8%8b%e4%bd%bf%e7%94% A8OPENCV Penis a small Mac white, recently started a MacBook Air, has no time to build a programming environment, the two days finally out of time to start using the Mac system. The current programming tools mainly for Eclipse and Xcode, I first chose to use Xcode, because I long-term use of C + + engaged in image processing work, so installation of OPENCV is the first step before programming began. system Environment: ML10.8.2Xcode version: 4.5.2OpenCV version: 2.4.3Eclipse version: Juno Service Release 1 here is a special reminder to you:OPENCV Chinese official website introduction of "OpenCV in Mac OS system installation Method" has been seriously expired, I have tried, failed, and this method is not OpenCV for Mac, but OpenCV for iOS, I hope you don't try to detour. http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=7524&start=0http://blog.csdn.net/eminia/article/details/6635117
In order to facilitate just contact with Mac friends, I am here first to explain under OpenCV in the form of a Mac. There are two main types: 1. OpenCV for Mac 2. OpenCV for iOS which iOS version is for your OpenCV to use on iphone or ipad projects, that is, to write programs running on iOS system. And the Mac version is to write running in the MAC system of the program used, this is very important, we must according to their own needs, and download the corresponding version. The author is because of the beginning to make it unclear the difference between the two versions and go a lot of detours, and now share with you, hoping to help.
below is a link to download the two versions of the OPENCV official website:the current version is 2.4.3 http://opencv.org/downloads.htmlOkay, here's the point, I'll start by introducing OpenCV for Mac, which is a C + + program that you can run on your Mac system.
First, install OpenCV for MAC 1. First download the OpenCV for Mac installation source file and unzip
2. Install the CMake program. The author uses homebrew, in the terminal input: "Brew install CMake", automatic installation CMake.
3. Enter the OpenCV folder after unpacking, create a new empty folder release, enter the folder, compile and install OPENCV, use the command as follows:
mkdir ReleaseCD Releasecmake-g "Unix makefiles" . Makesudo make install4. The installed LIB file is stored in the "/usr/local/lib" folder and the H file is stored in "/usr/local/include". At this point, the OpenCV for MAC installation is complete, the reference URL is as follows:http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installationhttp://tilomitra.com/opencv-on-mac-osx/
second, the use of OpenCV under the Mac 1. Create a new DisplayImage.cpp file with the following code
#include <cv.h>
#include
using 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", cv_window_autosize);
Imshow ("Display Image", image);
waitkey (0); return 0;} 2. Create a new CMakeLists.txt file with the following code:
Project (displayimage)find_package (OpenCV REQUIRED)add_executable (displayimage displayimage)target_link_libraries (DisplayImage ${opencv_libs}) 3. Compilation of two files
CD <DisplayImage_directory>
CMake. Make4. Run the compiled results
./displayimage lena.jpg
iii. using OpenCV in Xcode 1. Create an empty command line project. 2. Paste the following code in MAIN.CPP:////Main.cpp
Fbycharacternormalization
//
Created by Boyuan Feng on 13-1-24.
Copyright (c) 2013 Boyuan Feng. All rights reserved.
// #include <iostream>#include <opencv2/opencv.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv/cvaux.hpp>#include <fstream>using namespace std; #define BYTE unsigned char
int main (int argc, const char * argv[])
{//Insert code here ...#if 1//get the image from the directed pathiplimage* img = cvloadimage ("/users/boyuanfeng/aaa.bmp", 1);//nslog (IMG);//create A window to display the imageCvnamedwindow ("Picture", 1);//show the image in the windowcvshowimage ("Picture", IMG);//wait for the user to hit a keycvwaitkey (0);//delete the image and windowcvreleaseimage (&img);Cvdestroywindow ("picture");#endif//returnreturn 0;} 3. Add lib file: Right click on the project name, select "Add Files to.", enter "/" When the File selection dialog pops up, enter:/usr/local/lib, select all the Dylib files under the folder, and add to the project. 5. Add lib file lookup support: Click the project name file, go to the "Build Settings" tab, and enter "/usr/local/lib" in the "Library Search Paths" field.6. Add header file: Click on the project name file, go to the "Build Settings" tab, and in the "header Search Paths" field, enter: "/usr/local/include/usr/local/include/opencv "7. Compile and run the whole project, run successfully ~ ~
Iv. using OpenCV in Eclipse 1. Follow the normal steps of using Eclipse to build a Mac C + + project that contains a CPP file with the same code as in Xcode. 2. Right-click on the project name, select "Properties", select it from the property configuration page, click c + + Build, and select Settings in the dropdown options. In the tab on the right, select Tool Settings. 3. Select includes in the GCC C + + Compiler Options list to add the installed OpenCV header file directory in the Include Paths (-L):/usr/local/include/4. In the MacOS X c++linker option list, select Library and add the installed OpenCV lib file directory in the library search path (-L):/usr/local/lib/5. Select the library in the MacOS X c++linker option list, and in libraries (-L), click the "+" sign to add the Lib file you want to use (typically, the first three):opencv_core opencv_imgproc Opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_ Objdetect opencv_contrib opencv_legacy Opencv_flann6. Re-build all project, ~~* ^_^ *
(turn) Use OpenCV under Mac, use OpenCV under Xcode (very basic, verbose)