Xcode - Mac+Xcode+OpenCV 配置

Mac: 10.10.3
Xcode: Version 6.3.2
OpenCV: opencv-3.0.0-rc1

1. 下载OpenCV + CMake.

OpenCV: http://opencv.org/downloads.html
CMake: http://www.cmake.org/download/

2. 编译静态库(static), 动态库(shared)

使用cmake编译.

静态库

  1. 填写source code和build folder(staticlibs). 点击Configure按钮;
  2. 勾选, 并点击Generate按钮

    • 不勾选BUILD_SHARED_LIBS
    • 不勾选BUILD_TESTS
    • 添加SDK路径至CMAKE_OSX_SYSROOT, 例如
      /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
    • 添加x86_64至CMAKE_OSX_ARCHITECTURES, 依赖于当前系统
    • 不勾选WITH_1394
    • 不勾选WITH_FFMPEG
    • 不勾选WITH_IPP
  3. make文件

 - cd <path/to/your/opencv/staticlibs/folder/>  - make (较慢)

动态库

与静态库相似, 不同之处
1. 填写build folder(sharedlibs), 另换
2. 勾选BUILD_SHARED_LIBS
3. 进入sharedlibs里make
如图
Xcode - Mac+Xcode+OpenCV 配置_第1张图片

3. 验证

查看: /usr/local/lib和/usr/local/include, OpenCV相关文件是否存在.

4. 配置项目

设置Header Search Paths: /usr/local/include
设置Library Search Paths: /usr/local/lib
设置Other Linker Flags: (如图)

-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab

Xcode - Mac+Xcode+OpenCV 配置_第2张图片

5. 测试代码

//
// main.cpp
// OpenCV-Test
//
// Created by wang on 15/7/23.
// Copyright (c) 2015年 wang. All rights reserved.
//

#include <iostream>
#include <opencv2/opencv.hpp>

int main(int argc, const char * argv[]) {
    // insert code here...
    cv::Mat img = cv::imread("kkk.png");
    cv::imshow("kkk", img);
    cv::waitKey(0);
    std::cout << CV_VERSION << std::endl;

    return 0;
}

Xcode - Mac+Xcode+OpenCV 配置_第3张图片

你可能感兴趣的:(mac,xcode,opencv,Mystra)