ubuntu 18.04安装opencv-2.4.10遇错解决

安装opencv-2.4.10,执行make -j7时报如下错误:

问题1: ffmpeg错误

[ 17%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_exr.cpp.o
In file included from /home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp:60:0,
                 from /home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/cap_ffmpeg.cpp:45:
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/ffmpeg_codecs.hpp:104:7: error: ‘CODEC_ID_H264’ was not declared in this scope
     { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
       ^~~~~~~~~~~~~
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/ffmpeg_codecs.hpp:104:7: note: suggested alternative: ‘AV_CODEC_ID_H264’
     { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
       ^~~~~~~~~~~~~
       AV_CODEC_ID_H264
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/ffmpeg_codecs.hpp:105:7: error: ‘CODEC_ID_H264’ was not declared in this scope
     { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
       ^~~~~~~~~~~~~
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/ffmpeg_codecs.hpp:105:7: note: suggested alternative: ‘AV_CODEC_ID_H264’
     { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
       ^~~~~~~~~~~~~
       AV_CODEC_ID_H264
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/highgui/src/ffmpeg_codecs.hpp:106:7: error: ‘CODEC_ID_H264’ was not declared in this scope
     { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
       ^~~~~~~~~~~~~
......

临时解决办法:

在cmake时,将ffmpeg设置为OFF,即:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/hri/MyInstallSoftware/opencv-2.4.10/build/ -D BUILD_PYTHON_SUPPORT=ON -D ENABLE_PRECOMPILED_HEADERS=OFF -D FFMPEG=OFF ..

[注意:] 上述指令指定opencv安装在/home/hri/MyInstallSoftware/opencv-2.4.10/build/路径上

问题2: contrib模块错误

[ 96%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/colortracker.cpp.o
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp: In member function ‘void cv::ChamferMatcher::Matching::computeDistanceTransform(cv::Mat&, cv::Mat&, cv::Mat&, float, float, float)’:
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp:969:30: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
             if (&annotate_img!=NULL) {
                              ^
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp:1016:34: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
                 if (&annotate_img!=NULL) {
                                  ^
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp: In member function ‘cv::ChamferMatcher::Match* cv::ChamferMatcher::Matching::localChamferDistance(cv::Point, cv::Mat&, cv::Mat&, cv::ChamferMatcher::Template*, float)’:
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp:1111:25: error: the compiler can assume that the address of ‘orientation_img’ will never be NULL [-Werror=address]
     if (&orientation_img!=NULL) {
                         ^
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp:1111:5: warning: nonnull argument ‘orientation_img’ compared to NULL [-Wnonnull-compare]
     if (&orientation_img!=NULL) {
     ^~
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp: In member function ‘void cv::ChamferMatcher::Matching::computeDistanceTransform(cv::Mat&, cv::Mat&, cv::Mat&, float, float, float)’:
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp:1016:17: warning: nonnull argument ‘annotate_img’ compared to NULL [-Wnonnull-compare]
                 if (&annotate_img!=NULL) {
                 ^~
/home/hri/MyInstallSoftware/opencv-2.4.10/modules/contrib/src/chamfermatching.cpp:969:13: warning: nonnull argument ‘annotate_img’ compared to NULL [-Wnonnull-compare]
             if (&annotate_img!=NULL) {
             ^~

解决办法:

找到opencv-2.4.10/build/modules/contrib/CMakeFiles/opencv_contrib.dir/flags.make文件,删掉-Werror=address,然后重新 make -j7

你可能感兴趣的:(Ubuntu,相关软件安装)