gricode

grigory's place to post computer-related stuff.

Jul 27

Building OpenCV 2.3 on OSX 10.7 Lion

After upgrading to 10.7 (my 10.6 just refused to boot up one day, using odd looking kernel panic messages as a poor excuse for doing so), I decided to play with OpenCV.

First obvious step - compile it using CMake. First issue - “make” breaks around ~%50.

I got the following issue:

/Users/grisha/Downloads/OpenCV-2.3.0/modules/highgui/src/grfmt_png.cpp: In member function ‘virtual bool cv::PngEncoder::write(const cv::Mat&, const std::vector<int, std::allocator<int> >&)’:
/Users/grisha/Downloads/OpenCV-2.3.0/modules/highgui/src/grfmt_png.cpp:308: error: ‘MAX_MEM_LEVEL’ was not declared in this scope
/Users/grisha/Downloads/OpenCV-2.3.0/modules/highgui/src/grfmt_png.cpp:354: error: ‘Z_BEST_SPEED’ was not declared in this scope
/Users/grisha/Downloads/OpenCV-2.3.0/modules/highgui/src/grfmt_png.cpp:356: error: ‘Z_HUFFMAN_ONLY’ was not declared in this scope
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_png.o] Error 1
make[2]: *** Waiting for unfinished jobs….
Linking CXX shared library ../../lib/libopencv_video.dylib
[ 51%] Built target opencv_video
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2

After some googling, I found this discussion over at github: https://github.com/mxcl/homebrew/pull/6558. From reading that, it seems that the issue is with libpng not doing the right thing. Quick and dirty fix is to patch “grfmt_png.cpp” file with an explicit include statement for zlib.h, where the globals in question are declared.

So after adding “#include “zlib.h” to the top of OpenCV-2.3.0/modules/highgui/src/grfmt_png.cpp, OpenCV 2.3 compiled just fine on OSX 10.7.


  1. gricode posted this