标签:des http io os ar strong for div art
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.
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.
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.
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.
So we now have OpenCV built but we still have to link to the framework in our project.
/usr/local/lib
/usr/local/include
. This is where the header files for OpenCV were built.// 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
标签:des http io os ar strong for div art
原文地址:http://www.cnblogs.com/lakeone/p/3977948.html