安装OpenCV for MAC

本文详细介绍了如何在Mac OS系统上安装OpenCV并将其应用于XCode项目,包括安装步骤、配置环境、在XCode中使用OpenCV的完整流程,以及关键代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、安装OpenCV for MAC
 
1.     首先下载opencv for mac安装源文件,解压缩 2.     安装cmake程序。笔者使用的是Homebrew,在终端中输入:“brew install cmake”,自动安装cmake。 3.     进入存放解压后的opencv文件夹,新建一个空的文件夹release,进入该文件夹,编译安装opencv,使用命令如下:
       mkdir release
       cd release
       cmake -G "Unix Makefiles" ..        (注意后面的..其实就是上以级目录,那是 openCV source folder)
--------------------
(this is copy from http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation but had old, we
can use -G "Unix Makefiles")
cmake [<some optional parameters>] <path to the OpenCV source directory>

For example

cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
-------------------------- pls continue below 2 command,then the build process will be finished

       make
       sudo make install
4.     安装好的lib文件存放在“/usr/local/lib”文件夹,h文件存放在“/usr/local/include”。
       至此,opencv for Mac 安装完毕,参考的网址如下:

       http://tilomitra.com/opencv-on-mac-osx/
                                         install homebrew frist

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"



三、在XCode中使用OpenCV

1. 创建一个空的command line工程。
2. 在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 path
           IplImage* img = cvLoadImage("/Users/boyuanfeng/aaa.bmp", 1);
           //NSLog(img);
           //create a window to display the image
           cvNamedWindow("picture", 1);
           //show the image in the window
           cvShowImage("picture", img);
           //wait for the user to hit a key
           cvWaitKey(0);
           //delete the image and window
           cvReleaseImage(&img);
           cvDestroyWindow("picture");
#endif
           //return
           return 0;
}
 
3. 添加lib文件:右键点击工程名,选择“Add files to..”,在文件选择对话框弹出来时输入“/”,在弹出的路径框中输入:/usr/local/lib,全选该文件夹下的全部dylib文件,添加至工程。
5. 添加lib文件查找支持: 点击工程名文件,进入“Build Settings”选项卡,在“Library Search Paths”栏中输入“/usr/local/lib”
6. 添加头文件:点击工程名文件,进入“Build Settings”选项卡,在“Header Search Paths”栏中输入:“/usr/local/include   /usr/local/include/opencv”
7. 编译运行整个工程,运行成功~~




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值