Build Opencv 3 alpha with Python support
I looked up how homebrew builds opencv 2 and I made this line
cmake -DCMAKE_OSX_DEPLOYMENT_TARGET= -DPYTHON_LIBRARY="`python-config --prefix`/lib/libpython2.7.dylib" -DPYTHON_INCLUDE_DIR="`python-config --prefix`/include/python2.7" ..
With this cmake I get following result: (only important parts)
Found PythonInterp: /usr/local/bin/python2.7 (found suitable version "2.7.8", minimum required is "2.7")
-- Found PythonInterp: /usr/local/bin/python3 (found suitable version "3.4.1", minimum required is "3.4")
-- Could NOT find PythonLibs: Found unsuitable version "2.7.5", but required is exact version "3.4.1" (found PYTHON_LIBRARY-NOTFOUND)
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'numpy'
....
....
....
--
-- General configuration for OpenCV 3.0.0-dev =====================================
-- Version control: 458bde5
--
-- Platform:
-- Host: Darwin 13.3.0 x86_64
-- CMake: 3.0.1
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ Compiler: /usr/bin/c++ (ver 5.1.0.5030040)
-- C++ flags (Release): -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -fno-omit-frame-pointer -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -fno-omit-frame-pointer -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -fno-omit-frame-pointer -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -fno-omit-frame-pointer -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release):
-- Linker flags (Debug):
-- Precompiled headers: NO
--
-- OpenCV modules:
-- To be built: core flann imgproc imgcodecs videoio highgui ml features2d calib3d objdetect photo video shape stitching superres ts videostab
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: androidcamera cuda cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaoptflow cudastereo cudawarping cudev java python2 python3 viz
--
-- GUI:
-- QT: NO
-- Cocoa: YES
-- OpenGL support: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: build (ver 1.2.8)
-- JPEG: build (ver 90)
-- WEBP: build (ver 0.3.1)
-- PNG: build (ver 1.5.12)
-- TIFF: build (ver 42 - 4.0.2)
-- JPEG 2000: build (ver 1.900.1)
-- OpenEXR: build (ver 1.7.1)
-- GDAL: NO
--
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: NO
-- FFMPEG: YES
-- codec: YES (ver Unknown)
-- format: YES (ver Unknown)
-- util: YES (ver Unknown)
-- swscale: YES (ver Unknown)
-- gentoo-style: YES
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- QuickTime: NO
-- QTKit: YES
-- V4L/V4L2: NO/NO
-- XIMEA: NO
--
-- Other third-party libraries:
-- Use IPP: 8.1.1 [8.1.1]
-- at: /Users ...
no idea about apple, but the 1st thing i'd try (after cleaning up the build folder) is:
(and yes, "Unavailable" unfortunately means, it won't build any python support)
Yeah, I dived into CMakeList.txt and found this out already. Just in case I also put
BUILD_opencv_python2 = ON,
because it disables the whole module in specific for python2 CMakeList.txtif(NOT PYTHON2LIBS_FOUND OR NOT PYTHON2_NUMPY_INCLUDE_DIRS) ocv_module_disable(python2) endif()
And Now I see that I probably need to setup some additional variables like
PYTHON2_NUMPY_INCLUDE_DIRS
and maybe even all of these:PYTHON2_INCLUDE_PATH
PYTHON2_NUMPY_INCLUDE_DIRS
PYTHON2_EXECUTABLE
PYTHON2_DEBUG_LIBRARIES
PYTHON2_LIBRARIES
PYTHON2_PACKAGES_PATH
PYTHON2_VERSION_MAJOR
ah, yes, do so. if it does not find numpy, it will reject the python build
Looks like I shouldn't provide anything of this. https://github.com/Itseez/opencv/blob/79f593a42923a411fb0c421cd3b766acee004387/cmake/OpenCVDetectPython.cmake#L160 there is functionality that should detect all of this. ... now I should find out why it's not working =)