I’m using OpenCV for my 4th year design project and setting it up was a huge pain. I had to look through a whole bunch of different sites to figure out what to do. There are various ways to install it – through package managers such as Homebrew or Macports, or through the tarball + cmake. Now that I’ve got it set up, I decided to write this little post to explain to others how to go about setting it up.

Note: This method does not set up the Python bindings for OpenCV (still working on that). It only sets up the C++ framework. Also, I tested this on OSX Lion, but it should apply to Snow Leopard or Leopard. Also you will need XCode installed for any of this to work (but you knew that, right?)

On that note, let’s get started.

Download a Package Manager

It’s between Macports, Fink or Homebrew. I used Macports, so I’d recommend that. Download the .dmg file, then install it. You can check to see if it installed successfully by opening your terminal and typing port.

Download the OpenCV Tarball

You can get that from here. Look for the Linux or Mac version. Unzip it after you download it into a folder.

Get cmake

In your terminal, type in the following:
sudo port install cmake
This will go fetch cmake and its dependencies and install them onto your system. You can check to see that cmake is installed by typing cmake in a new terminal window.

Build OpenCV

We are going to build OpenCV using cmake. In terminal, navigate to the folder where OpenCV was extracted to. Type in the following:

# make a separate directory for building
mkdir build
cd build
cmake -G "Unix Makefiles" ..

Now, we can make OpenCV. Type the following in:

make -j8
sudo make install

This should now build OpenCV into your /usr/local/ directory.

Make A Sample OpenCV Project

So we now have OpenCV built but we still have to link to the framework in our project.

  1. Start a new XCode Command Line Tool project.
  2. We have to link the .dylib files provided by OpenCV into our project. To do this, right click on the project, and click “Add files to..”
  3. When Finder pops up, hit “/” to bring up the navigation panel.
  4. Type in /usr/local/lib
  5. Add in all the .dylib files that you need. To prevent linker errors, I recommend you initially add ALL the files ending in “…2.3.1.dylib”. There should be a dozen or so. If you know what you need, you can obviously pick and choose.
  6. Now, you should have a bunch of .dylib files in your project. Feel free to move them to a separate group within your project.
  7. Click on the project file and go to “Build Settings”.
  8. Search for “Header Search Paths”
  9. Change the path to  /usr/local/include. This is where the header files for OpenCV were built.
  10. Open main.cpp
  11. Copy the following code snippet. This snippet should load a .jpg image andsave it as a .png image.
// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.hpp> int main(int argc, char** argv)
{
IplImage * pInpImg = 0; // Load an image from file - change this based on your image name
pInpImg = cvLoadImage("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!pInpImg)
{
fprintf(stderr, "failed to load input image\n");
return -1;
} // Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if( !cvSaveImage("my_image_copy.png", pInpImg) )
{
fprintf(stderr, "failed to write image file\n");
} // Remember to free image memory after using it!
cvReleaseImage(&pInpImg); return 0;
}

And there you go. That should be working for you. If it’s not, leave a comment below with the error you get and I’ll try looking into it for you. Hopefully, this helps save you some time.

On that note, here is a good OpenCV Tutorial.

Please read before commenting: Hey guys – thanks a lot for all the comments on this thread. Unfortunately, it’s been a long time since I looked into OpenCV so I don’t remember the details anymore. If you have questions, skim through the comments because many people have posted their solutions. Feel free to comment if you don’t find an answer. On the other hand, if you made some small change that made this work – please add it to the comments so others can find it useful. Thanks!

OpenCV on Mac OSX: A step-by-step guide的更多相关文章

  1. 在Mac OSX 10.10 上安装opencv

    http://blog.csdn.net/wdkirchhoff/article/details/41910553 在Mac OSX上如果想使用OpenCV,可以通过自己手动编译源码的方式,但比较繁琐 ...

  2. 深度学习框架-caffe安装-环境[Mac OSX 10.12]

    深度学习框架-caffe安装 [Mac OSX 10.12] [参考资源] 1.英文原文:(使用GPU) [http://hoondy.com/2015/04/03/how-to-install-ca ...

  3. 深度学习框架-caffe安装-Mac OSX 10.12

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...

  4. Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1

    摘要: Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1 安装遇到问题请文末留言. 悦动智能公众号:aibbtcom AI这个概念好像突然就 ...

  5. mac osx下django-admin.py出现的问题

    mac osx 下面用django-admin.py创建项目的时候,没创建成功出现django-admin.py编辑文件,这主要的原因是mac osx下面django-admin.py被重命名为dja ...

  6. mac osx 上面部署Django项目 apache+mysql+mod_wsgi

    1.安装Xcode command line tools 首先,编译mysql和Homebrew需要用到Xcode command line tools,所以首先安装command line tool ...

  7. Webstorm 10 for mac osx 注册机,序列号,kegen

    小菜最近get到mac体验机会,早就耳闻mac非常适合做开发,于是迫不及待的安装各种开发工具,不知不觉,轮到前端开发神器webstorm了,看了一下官网的价格,心拔凉拔凉的. 果断搜索注册机,搜到的结 ...

  8. Step by step Dynamics CRM 2011升级到Dynamics CRM 2013

    原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...

  9. Step by Step 创建一个新的Dynamics CRM Organization

    原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...

随机推荐

  1. exe取消动态基址

    动态基址开启后,在动态调试是想要和ida静态分析中的地址对应还要进行一步计算,取消动态基址便可以剩下很多时间. 只要修改pe文件头中的Characteristics低位置1 1 typedef str ...

  2. sqli-labs系列——第二关

    less2 and 1=1有回显,and 1=2无回显,为数值型注入 order by 4–+报错,有3行 查询数据库名 ?id=0' union select 1,(select group_con ...

  3. 移动端调试vConsole

    当我们在进行移动端开发的时候,经常会出现在pc显示正常,在移动端却各种异常的情况.这时候我们在手机上又看不到error log. 所以我们就需要vConsole这样一个移动端开发神器. 那具体要怎么使 ...

  4. 如何使用Topshelf与.NET泛型主机建立Windows服务

    1 前置阅读 在阅读本文章之前,你可以先阅读: Topshelf一个用于使用.NET构建Windows服务框架 2 使用 2.1 创建应用程序 首先,创建一个新的控制台应用程序并从nuget获取Top ...

  5. ELK7.11.2版本安装部署及ElastAlert告警相关配置

    文档开篇,我还是要说一遍,虽然我在文档内容中也会说好多遍,但是希望大家不要嫌我墨迹: 请多看官方文档,请多看命令行报错信息,请多看日志信息,很多时候它们比百度.比必应.比谷歌有用: 请不要嫌麻烦,打开 ...

  6. 从应用层到网络层排查 Dubbo 接口超时全记录

    大家好,我是坤哥 我们常说面试造火箭,很多人对此提出质疑,相信大家看了这篇文章会明白面试造火箭的道理,这篇排查问题的技巧涉及到索引,GC,容器,网络抓包,全链路追踪等基本技能,没有这些造火箭的本事,排 ...

  7. 自动化kolla-ansible部署ubuntu20.04+openstack-victoria之替换logo-13

    自动化kolla-ansible部署ubuntu20.04+openstack-victoria之替换logo-13 欢迎加QQ群:1026880196 进行交流学习 替换 openstack das ...

  8. 【pytest官方文档】解读fixtures - 11. fixture的执行顺序,3要素详解(长文预警)

    当pytest要执行一个测试函数,这个测试函数还请求了fixture函数,那么这时候pytest就要先确定fixture的执行顺序了. 影响因素有三: scope,就是fixture函数的作用范围,比 ...

  9. 今日浅谈循环 for与while

    昨天写的条件分支结构与今日写的循环是编程两个最基本的也非常重要的个结构 for循环 for循环可以从一个元组(tuple),列表(list),字典(dict),集合(set),字符串(string') ...

  10. 一文带你掌握MySQL查询优化技能

    查询优化本就不是一蹴而就的,需要学会使用对应的工具.借鉴别人的经验来对SQL进行优化,并且提升自己. 分享一套博主觉得讲的很详细很实用的MySQL教程给大家,可直接点击观看! https://www. ...