OpenCV on Mac OSX: A step-by-step guide
来源:互联网 发布:.net软件开发工程师 编辑:程序博客网 时间:2024/06/11 01:22
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 buildingmkdir buildcd buildcmake -G "Unix Makefiles" ..
Now, we can make OpenCV. Type the following in:
make -j8sudo 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 and save 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.
Edit: Oops, looks like that link is dead now.
- OpenCV on Mac OSX: A step-by-step guide
- How to Install the ELK Stack on AWS: A Step-By-Step Guide
- Creating Games in C++ : A Step-by-Step Guide
- Deploying Rails Applications: A Step-by-Step Guide
- Tomcat Clustering - A Step By Step Guide --转载
- Building Android for Qemu: A Step-by-Step Guide
- CGAL Arrangements and Their Applications: A Step-By-Step Guide
- subversion on Mac OS X step by step
- Opencv step by step - ROI
- Opencv step by step - 绘图
- Opencv step by step - 配置文件
- A step-by-step guide to the use of the Intel OpenCV library and the Microsoft DirectShow technology
- Mac OS X - A step-by-step guide to installing Go and building your first web service
- Step-by-step Install Guide for Ubuntu
- A step-by-step guide for debugging native code (Sequoyah/ndk guide)
- Step by Step Guide on Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE (Doc ID
- Step-by-step guide on File-to-IDoc using SAP PI 7.0
- Running OpenBTS with the Nuand bladeRF on Ubuntu (The Definitive and Step by Step Guide)
- wrk 压力测试
- HOJ cake
- linux系统下的vim编辑器的用法
- 编译新版本spice-gtk
- 226. Invert Binary Tree | 翻转二叉树
- OpenCV on Mac OSX: A step-by-step guide
- dlnd-your-first-neural-network中反向传播的笔记
- oracle简单命令
- 62. Unique Paths -Medium
- c#虚拟路径
- 5.CSS图像绘制之:条纹背景
- 栈与队列(六)之总结篇
- linux下修改oracle密码报错修改密码问题解决
- python基础-------类