首先建立工作空间并编译:
mkdir -p calibration_ws/src
cd calibration_ws/src
git clone https://github.com/gaowenliang/code_utils.git
cd ..
catkin_make
编译过程中遇到的问题:
问题一:
/home/usrname/calibration_ws/src/code_utils/include/code_utils/backward.hpp:216:12: fatal error: elfutils/libdw.h: 没有那个文件或目录
216 | # include <elfutils/libdw.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
解决方法:
sudo apt-get install libdw-dev
问题二:
usr/local/include/ceres/internal/fixed_array.h:39:10: fatal error: glog/logging.h: 没有那个文件或目录
39 | #include "glog/logging.h"
| ^~~~~~~~~~~~~~~~
compilation terminated.
解决方法:
sudo apt-get install libgoogle-glog-dev
问题三:
home/usrname/calibration_ws/src/code_utils/src/sumpixel_test.cpp:2:10: fatal error: backward.hpp: 没有那个文件或目录
2 | #include "backward.hpp"
| ^~~~~~~~~~~~~~
compilation terminated.
解决方法:在code_utils的CMakeLists.txt文件中添加路径即可解决
include_directories("include/code_utils")
问题四:
home/usrname/calibration_ws/src/code_utils/src/mat_io_test.cpp:33:47: error: ‘CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope
33 | Mat img1 = imread( "/home/gao/IMG_1.png", CV_LOAD_IMAGE_UNCHANGED );
| ^~~~~~~~~~~~~~~~~~~~~~~
/home/usrname/calibration_ws/src/code_utils/src/sumpixel_test.cpp:84:47: error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
84 | Mat img1 = imread( "/home/gao/IMG_1.png", CV_LOAD_IMAGE_GRAYSCALE );
| ^~~~~~~~~~~~~~~~~~~~~~~
/home/usrname/calibration_ws/src/code_utils/src/sumpixel_test.cpp:94:35: error: ‘CV_MINMAX’ was not declared in this scope; did you mean ‘CV_MMX’?
94 | normalize( img, img2, 0, 255, CV_MINMAX );
| ^~~~~~~~~
| CV_MMX
/home/usrname/calibration_ws/src/code_utils/src/sumpixel_test.cpp: In function ‘void test2()’:
/home/fcwd/calibration_ws/src/code_utils/src/sumpixel_test.cpp:107:47: error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
107 | Mat img1 = imread( "/home/gao/IMG_1.png", CV_LOAD_IMAGE_GRAYSCALE );
| ^~~~~~~~~~~~~~~~~~~~~~~
/home/usrname/calibration_ws/src/code_utils/src/sumpixel_test.cpp:117:35: error: ‘CV_MINMAX’ was not declared in this scope; did you mean ‘CV_MMX’?
117 | normalize( img, img2, 0, 255, CV_MINMAX );
| ^~~~~~~~~
| CV_MMX
解决方法:
出现该问题是因为opencv4.x以上,有些宏和API的名字有所更改,可以按照以下对应关系更改:
CV_LOAD_IMAGE_UNCHANGED 改为 cv::IMREAD_UNCHANGED
CV_LOAD_IMAGE_GRAYSCALE 改为 cv::IMREAD_GRAYSCALE
CV_LOAD_IMAGE_COLOR 改为 cv::IMREAD_COLOR
CV_LOAD_IMAGE_ANYDEPTH 改为 cv::IMREAD_ANYDEPTH
CV_MINMAX 改为 CV_MMX
全部更改后再次编译即可成功。