OpenCV on Mac OSX: A step-by-step guide
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.
- Start a new XCode Command Line Tool project.
- 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..”
- When Finder pops up, hit “/” to bring up the navigation panel.
- Type in
/usr/local/lib
- 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.
- Now, you should have a bunch of .dylib files in your project. Feel free to move them to a separate group within your project.
- Click on the project file and go to “Build Settings”.
- Search for “Header Search Paths”
- Change the path to
/usr/local/include
. This is where the header files for OpenCV were built. - Open main.cpp
- 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的更多相关文章
- 在Mac OSX 10.10 上安装opencv
http://blog.csdn.net/wdkirchhoff/article/details/41910553 在Mac OSX上如果想使用OpenCV,可以通过自己手动编译源码的方式,但比较繁琐 ...
- 深度学习框架-caffe安装-环境[Mac OSX 10.12]
深度学习框架-caffe安装 [Mac OSX 10.12] [参考资源] 1.英文原文:(使用GPU) [http://hoondy.com/2015/04/03/how-to-install-ca ...
- 深度学习框架-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 ...
- Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1
摘要: Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1 安装遇到问题请文末留言. 悦动智能公众号:aibbtcom AI这个概念好像突然就 ...
- mac osx下django-admin.py出现的问题
mac osx 下面用django-admin.py创建项目的时候,没创建成功出现django-admin.py编辑文件,这主要的原因是mac osx下面django-admin.py被重命名为dja ...
- mac osx 上面部署Django项目 apache+mysql+mod_wsgi
1.安装Xcode command line tools 首先,编译mysql和Homebrew需要用到Xcode command line tools,所以首先安装command line tool ...
- Webstorm 10 for mac osx 注册机,序列号,kegen
小菜最近get到mac体验机会,早就耳闻mac非常适合做开发,于是迫不及待的安装各种开发工具,不知不觉,轮到前端开发神器webstorm了,看了一下官网的价格,心拔凉拔凉的. 果断搜索注册机,搜到的结 ...
- Step by step Dynamics CRM 2011升级到Dynamics CRM 2013
原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...
- Step by Step 创建一个新的Dynamics CRM Organization
原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...
随机推荐
- c++反汇编 switch
switch 线性处理 24: int nIndex = 0; 01377EBE C7 45 F8 00 00 00 00 mov dword ptr [nIndex],0 25: scanf(&qu ...
- 面试题:ApplicationContext和BeanFactory两种容器区别
ApplicationContext和BeanFactory两种容器区别 BeanFactory是ApplicationContext容器的父接口 BeanFactory(多例模式): BeanFac ...
- java例题_14 该日期一年中的第几天问题
1 /*14 [程序 14 求日期] 2 题目:输入某年某月某日,判断这一天是这一年的第几天? 3 程序分析:以 3 月 5 日为例,应该先把前两个月的加起来,然后再加上 5 天即本年的第几天,特殊情 ...
- 力扣 - 92. 反转链表II
目录 题目 思路1(迭代) 代码 复杂度分析 思路2(递归) 代码 复杂度分析 题目 92. 反转链表 II 思路1(迭代) 将反转链表分成3个部分:前一段未反转的部分.待反转链表部分.后一段未反转部 ...
- 计算机体系结构——CH3存储系统
计算机体系结构--CH3存储系统 右键点击查看图像,查看清晰图像 X-mind 计算机体系结构--CH3存储系统 存储系统原理 主要性能 速度 容量 价格 两种存储系统 Cache与主存储器 虚拟存储 ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...
- Swagger3注解使用
这里只简单的说一下swagger的传值,返回值时注解的使用演示.相关注解及说明见其他文章 接收参数方式1 我们常规接收参数,可以使用一个类,类里面把属性作为接收的参数,使用注解对属性进行说明.但是这种 ...
- 免费开源的客服系统 Linux 服务器环境安装部署过程
最近因为项目需要,要找一款在线客服系统集成在 APP 中使用,而且涉及到生意开单,客服系统必须稳定可靠.另外甲方要求,必须支持 Linux 服务器环境. 我们以 Ubuntu 18.04 为例把安装部 ...
- 000 - 准备工作ADB wifi连接多台鸿蒙设备进行调试
首先将两台鸿蒙设备插入电脑的usb上 查看两台鸿蒙设备的deviceid C:\Users\Administrator>adb devices * daemon not running; sta ...
- 【Azure 应用服务】App Service/Azure Function的出站连接过多而引起了SNAT端口耗尽,导致一些新的请求出现超时错误(Timeout)
问题描述 当需要在应用中有大量的出站连接时候,就会涉及到SNAT(源地址网络转换)耗尽的问题.而通过Azure App Service/Function的默认监控指标图表中,却没有可以直接查看到SNA ...