我正在尝试为anaconda3安装构建opencv 3.1.0,并且构建失败:
[ 94%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
/home/mikel/Soft/opencv/modules/python/src2/cv2.cpp:6:20: fatal error: Python.h: No such file or directory
compilation terminated.
我将opencv和opencv-contrib都克隆到了3.1.0版本git checkout 3.1.0
中,并且尝试在~/Soft/opencv/build
中安装opencv-contrib的地方进行构建~/Soft/opencv-contrib
。我正在使用i7-4960X运行Ubuntu GNOME 15.10。
我的主要目标是使opencv在anaconda3安装中工作,因此我的cmake命令如下:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/Soft/opencv_contrib/modules \
-D PYTHON3_EXECUTABLE=/home/mikel/anaconda3/bin/python3.5 \
-D PYTHON3_INCLUDE_DIR=/home/mikel/anaconda3/include/ \
-D PYTHON3_LIBRARY=/home/mikel/anaconda3/lib/libpython3.5m.so \
-D PYTHON3_PACKAGES_PATH=/home/mikel/anaconda3/lib/python3.5/site-packages/ \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/home/mikel/anaconda3/lib/python3.5/site-packages/numpy/core/include \
-D PYTHON_DEFAULT_AVAILABLE=/home/mikel/anaconda3/bin/python3.5 \
-D BUILD_EXAMPLES=ON ..
我的cmake命令的输出在这里:http : //pastebin.com/qtd1wyMb-据我所知一切正常。
然后make -j12
,我运行安装opencv,并在出现一些警告后运行良好,直到94%,我得到以下输出:
Scanning dependencies of target opencv_python3
[ 94%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
/home/mikel/Soft/opencv/modules/python/src2/cv2.cpp:6:20: fatal error: Python.h: No such file or directory
compilation terminated.
modules/python3/CMakeFiles/opencv_python3.dir/build.make:278: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o' failed
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
CMakeFiles/Makefile2:18929: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_main.cpp.o
[ 94%] Built target opencv_test_optflow
[ 94%] [ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp.o
Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp.o
[ 94%] [ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/ModelRegistration.cpp.o
Building CXX object modules/stitching/CMakeFiles/opencv_test_stitching.dir/test/ocl/test_warpers.cpp.o
[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/opencl/perf_stitch.cpp.o
Linking CXX executable ../../bin/cpp-example-bgfg_segm
Linking CXX executable ../../bin/cpp-example-autofocus
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp.o
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/ModelRegistration.cpp.o
[ 94%] Linking CXX executable ../../bin/opencv_test_tracking
Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/Mesh.cpp.o
[ 94%] Built target example_bgfg_segm
[ 94%] [ 94%] Built target example_autofocus
Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/Model.cpp.o
[ 94%] [ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp.o
Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/PnPProblem.cpp.o
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/Mesh.cpp.o
[ 94%] Built target opencv_test_tracking
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/Model.cpp.o
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/PnPProblem.cpp.o
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp.o
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/RobustMatcher.cpp.o
[ 94%] Building CXX object samples/cpp/CMakeFiles/cpp-tutorial-pnp_detection.dir/tutorial_code/calib3d/real_time_pose_estimation/src/RobustMatcher.cpp.o
[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/opencl/perf_warpers.cpp.o
Linking CXX executable ../../bin/cpp-example-3calibration
[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_test_stitching.dir/test/test_main.cpp.o
[ 94%] Built target example_3calibration
Linking CXX executable ../../bin/opencv_test_stitching
[ 94%] Built target opencv_test_stitching
Linking CXX executable ../../bin/cpp-tutorial-pnp_registration
[ 94%] Built target cpp-tutorial-pnp_registration
Linking CXX executable ../../bin/cpp-tutorial-pnp_detection
[ 94%] Built target cpp-tutorial-pnp_detection
Linking CXX executable ../../bin/opencv_perf_stitching
[ 94%] Built target opencv_perf_stitching
Makefile:146: recipe for target 'all' failed
make: *** [all] Error 2
make的完整输出在这里供参考:http : //pastebin.com/1zNgsckZ
看来我的问题是因为我使用的是anaconda3路径,而不是标准的python3路径,所以它不再找到Python.h。但是,当我使用系统python3安装进行安装时,无法将opencv导入需要的anaconda中。
我已经安装了python3-dev和python-dev,所以Python.h应该在我的机器上。为了使openCV找到Python.h,我需要更改什么?
编辑:我发现Anaconda3的Python.h在anaconda3 / include / python3.5m /中,所以我设置了PYTHON3_INCLUDE_DIR=anaconda3/include/python3.5m/
,现在我得到了另一个错误:
Scanning dependencies of target opencv_python3
Linking CXX executable ../../bin/opencv_test_optflow
[ 91%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
In file included from /home/mikel/Soft/opencv/build/modules/python3/pyopencv_generated_include.h:11:0,
from /home/mikel/Soft/opencv/modules/python/src2/cv2.cpp:12:
/home/mikel/Soft/opencv_contrib/modules/hdf/include/opencv2/hdf/hdf5.hpp:40:18: fatal error: hdf5.h: No such file or directory
compilation terminated.
modules/python3/CMakeFiles/opencv_python3.dir/build.make:278: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o' failed
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
CMakeFiles/Makefile2:18929: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
我解决了这个问题。问题是PYTHON3_INCLUDE_DIR
设置为~/anaconda3/include
Anaconda的Python.h实际上在其中~/anaconda3/include/python3.5m
。设置可以PYTHON3_INCLUDE_DIR=anaconda3/include/python3.5m/
解决此问题,因为现在可以看到Python.h
但是,这导致了另一个问题,其中某些.h文件(例如hdf5.h
和)H5public.h
对于OpenCV不再可见,因为这些文件位于主anaconda3 / include /目录中,而不在子文件夹中。
解决方案是将include/
目录中的所有.h文件复制到include/python3.5m
目录中(将这两个文件的内容复制到另一个目录中,并将其设置为路径也可以使用),以便所有.h文件都位于同一文件夹中到编译器。OpenCV现在开始构建!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句