Lecture 14 of Visual SLAM--Practical Operation and Pit Avoidance of ch5
1. Preparatory work before practical operation
-
Install OpenCV
Ubuntu18 reference: Opencv4 installation and C++ configuration under Ubuntu 18.04
Ubuntu20 reference: Ubuntu 20.04 build OpenCV 4.5.0 & C++ environment
description: OpenCV provides a large number of open source image algorithms, which is an image processing algorithm library widely used in computer vision.
Note: Different OpenCV versions may have different statements, just make changes at that time. -
Enter the ch5 folder in the terminal, and execute the following commands in order to compile.
mkdir build
cd build
cmake ..
//注意,j4还是其他主要看自己的电脑情况
make -j4
- Execute in the build file.
Two, each practical operation
1. Image in computer
- The basic method of using OpenCV - operating the OpenCV image Enter the imageBasics execution statement
in the build : (here you can also directly change the statement in the file to obtain the fixed position of the image)
./imageBasics /home/fighter/slam/slambook2/ch5/imageBasics/ubuntu.png
Result after execution:
First, the first picture pops up, press any key to pop up the second picture, then press any key, 3 and 4 appear at the same time.
While popping up the picture, the terminal outputs the following:
The width of the image is 1200, the height is 674, and the number of channels is 3. It takes
1e-07 seconds to traverse the image.
- Image undistortion
Enter imageBasics in build, pay attention to change the path of the image file in undistortImage.cpp. After the modification, remember to go to build to compile make.
Execution statement: ./undistortImage
Execution result:
2.3D vision
-
Binocular vision
Enter stereo in build, pay attention to change the path of the image file in stereoVision.cpp. After the modification, remember to go to build to compile make.
Execution statement: ./stereoVision
Execution result:
(1) Left eye image
(2) Right eye image
(3) Disparity map of SGBM (Because some left eye sees it but the right eye does not, so the corresponding inspection is empty)
(4) Point cloud map
-
RGB-D vision
Enter stereo in build, pay attention to change the path of the image file in joinMap.cpp.
Change lines 21-30 of the code to look like this. Note: The path needs to be changed to your own! ! ! After the modification, remember to go to build to compile make.
ifstream fin("/home/fighter/slam/slambook2/ch5/rgbd/pose.txt");
if (!fin) {
cerr << "请在有pose.txt的目录下运行此程序" << endl;
return 1;
}
for (int i = 0; i < 5; i++) {
boost::format fmt("/home/fighter/slam/slambook2/ch5/rgbd/%s/%d.%s"); //图像文件格式
colorImgs.push_back(cv::imread((fmt % "color" % (i + 1) % "png").str()));
depthImgs.push_back(cv::imread((fmt % "depth" % (i + 1) % "pgm").str(), -1)); // 使用-1读取原始图像
Execution statement: ./joinMap
Execution result:
At the same time, the terminal will output:
转换图像中: 1
转换图像中: 2
转换图像中: 3
转换图像中: 4
转换图像中: 5
点云共有1081843个点.
3. Problems encountered
- Problem: When executing cmake, the error shown in the figure below appears:
Solution: This is just a warning. Through observation, we can see that it is just a warning for project developers. There are two approaches here.
- Just ignore it, it won't cause any impact here
- In the CMakeLists.txt file in the workspace, add project (chapter5) in the second line according to the warning prompt , and the contents of the brackets can be filled in arbitrarily in this practice.