OpenCV installation steps:
1. Install MacPorts
2. Install CMake by "sudo port install cmake"
3. Get OpenCV source, http://opencv.willowgarage.com/wiki/InstallGuide, and untar it
4. Build OpenCV
Go to the folder where you untar the OpenCV source to.
Make a separate folder for building
. make build
. cd build
. cmake -G "Unix Makefiles" ..
Now make OpenCV
. make -j8
. sudo make install
The OpenCV will be installed to /usr/local
5. Done installing the OpenCV on Mac OS X
Create a sample project on XCode with OpenCV
1. Start a new XCode "Command Line Tool" project with Type C++
2. Add all the libopencv*.dylib (or the ones you need) into the project from /usr/local/lib with "Copy items into destination group's folder (if needed)" checked
3. Add "/usr/local/include" into "Header Search Path" in Build Settings of project
4. Add "/usr/local/lib" into "Library Search Path" in Build Settings of project
5. Either 4.1 or 4.2
4.1 Select "libstdc++ (GNU C++ standard library)" instead of "libc++ (LLVM C++ standard library with C++11 support)" in "Apple LLVM compiler 4.2 - Language" in Build Settings
4.2 Select "LLVM GCC 4.2" instead of "Default compiler (Apple LLVM compiler 4.2)" in "Compiler for C/C++/Objective-C" in Build Settings
6. Write some codes to test OpenCV
#include
#include
#include "opencv2/core/core.hpp"
using namespace cv ;
int main(int argc, char** argv)
{
#if 0
//get the image from the directed path
IplImage* img = cvLoadImage("/Users/Howard/Desktop/Codes/OpenCV/CV/Lena_512.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");
#else
Mat img = imread("/Users/Howard/Desktop/Codes/OpenCV/CV/Lena_512.bmp", CV_LOAD_IMAGE_UNCHANGED);
if (img.data == NULL)
{
printf("\n Image cannot be loaded") ;
system("pause");
return -1;
}
namedWindow("OrgImage", CV_WINDOW_AUTOSIZE);
imshow("OrgImage", img);
waitKey(0) ;
#endif
}
7. That's all
No comments:
Post a Comment