install opencv
You only need to install Cmake
above 3.5.1. You can check your own cmake version first. Generally, you don’t need this step to install
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake
install dependencies
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran libgtk2.0-dev libjpeg-dev libpng-dev
Download opencv package
visit link, download
https://opencv.org/releases/page/2/
Click "Source" to download, and download the corresponding version according to your own needs.
Remember that the corresponding version in the following code must be changed accordingly. Here is 4.4.0 as an example. The actual test is 3.4.12. Just change the corresponding version number, and everything else is fine. Same,
enter this folder after decompression, open a terminal in this folder,
and execute the following commands in order to compile
mkdir build
cd build
sudo mkdir /usr/local/opencv4.4.0
Special reminder for pre-compilation If you are installing this by reading the book of visual slam, it is recommended to install more viz modules in the general installation situation, but I have only tried it on opencv3, and I have not tried opencv4. It is recommended to use opencv3. Pre-compilation uses Method (1)
Of course, if you just install opencv without the viz module, you can directly use method (2), even if the difference is that other modules can be recompiled later, but it will take some time
Method (1)
First install the dependencies required by viz
sudo apt-get install libvtk6-dev
precompile again
cmake -DWITH_VTK=ON -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.4.12 ..
Method (2)
Direct precompilation
cmake -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.4.0 ..
compile
sudo make -j4
sudo make install
Configure environment variables
sudo gedit /etc/ld.so.conf.d/open.conf
Add in the pop-up file, then save and exit
/usr/local/opencv4.4.0/lib
terminal input
sudo ldconfig
sudo gedit /etc/bash.bashrc
Add in the pop-up file, then save and exit
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv4.4.0/lib/pkgconfig
export PKG_CONFIG_PATH
Type in terminal
source /etc/bash.bashrc
sudo apt-get install mlocate
sudo updatedb
You can use the following command to view the installed opencv version
pkg-config --modversion opencv
Test whether the installation is complete (find a picture by yourself and put it in the corresponding path)
test.cpp
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
int main()
{
cv::Mat img = cv::imread("../test1.png");
//namedWindow("DisplayImage");
cv::imshow("test", img);
cv::waitKey();
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(test_install)
find_package(OpenCV REQUIRED) #加这一句
include_directories(${
OpenCV_INCLUDE_DIRS}) #加这一句
set(CMAKE_CXX_STANDARD 11)
add_executable(test_install test.cpp)
target_link_libraries(test_install ${
OpenCV_LIBS}) #加这一句 ```
After the compilation output is successful, a picture will be displayed, indicating that the opencv installation is successful
Install the Sophus library
git clone https://github.com/strasdat/Sophus.git
cd Sophus
git checkout a621ff
mkdir build & cd build
cmake ..
make
If your ubuntu version is relatively new, there will be such an error
/Sophus/sophus/so2.cpp:32:26: error: lvalue required as left operand of assignment
unit_complex_.real() = 1.;
/Sophus/sophus/so2.cpp:33:26: error: lvalue required as left operand of assignment
unit_complex_.imag() = 0.;
Solution:
Find the so2.cpp file in the /Sophus/sophus directory, the following code:
SO2::SO2()
{
unit_complex_.real() = 1.;
unit_complex_.imag() = 0.;
}
Modify it to:
SO2::SO2()
{
unit_complex_.real(1.);
unit_complex_.imag(0.);
}
Just make it again