双目SLAM(2) opencv

时间:2021-01-26 08:39:00

一步步实现ORB-SLAM2

http://www.fengbing.net/

1 opencv 测试

http://blog.csdn.net/u010480194/article/details/54288926

测试安装的opencv 版本

my_pc:~/Desktop$ python
Python 2.7.6
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'2.4.9'
>>>

OpenCV测试:
在某个目录下(如OPENCV_TEST)建立一个test.cpp文件:

gedit test.cpp

#include <cv.h>
#include <highgui.h> using namespace cv; int main(int argc, char* argv[])
{
Mat image;
image = imread("1.jpg");
namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(0);
return 0;
}

写一个cmake的makefile,也叫CMakeLists.txt:

gedit CMakeLists.txt

project(test)
find_package(OpenCV REQUIRED)
add_executable(test test)
target_link_libraries(test ${OpenCV_LIBS})
cmake_minimum_required(VERSION 2.8)

编译+运行

cmake .
make
./test

得到可执行文件

双目SLAM(2)  opencv

2 SGBM 双目计算深度

http://blog.csdn.net/liulina603/article/details/53302168

(1)在上一步的基础上,test.cpp代码替换

    #include <highgui.h>
#include <cv.h>
#include <cxcore.h>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{ IplImage * img1 = cvLoadImage("left.png",0);
IplImage * img2 = cvLoadImage("right.png",0);
cv::StereoSGBM sgbm;
int SADWindowSize = 9;
sgbm.preFilterCap = 63;
sgbm.SADWindowSize = SADWindowSize > 0 ? SADWindowSize : 3;
int cn = img1->nChannels;
int numberOfDisparities=64;
sgbm.P1 = 8*cn*sgbm.SADWindowSize*sgbm.SADWindowSize;
sgbm.P2 = 32*cn*sgbm.SADWindowSize*sgbm.SADWindowSize;
sgbm.minDisparity = 0;
sgbm.numberOfDisparities = numberOfDisparities;
sgbm.uniquenessRatio = 10;
sgbm.speckleWindowSize = 100;
sgbm.speckleRange = 32;
sgbm.disp12MaxDiff = 1;
Mat disp, disp8;
int64 t = getTickCount();
sgbm((Mat)img1, (Mat)img2, disp);
t = getTickCount() - t;
cout<<"Time elapsed:"<<t*1000/getTickFrequency()<<endl;
disp.convertTo(disp8, CV_8U, 255/(numberOfDisparities*16.)); namedWindow("left", 1);
cvShowImage("left", img1);
namedWindow("right", 1);
cvShowImage("right", img2);
namedWindow("disparity", 1);
imshow("disparity", disp8);
waitKey();
imwrite("sgbm_disparity.png", disp8);
cvDestroyAllWindows();
return 0;
}

(2)编译+运行

cmake .
make
./test

双目SLAM(2)  opencv

双目SLAM(2)  opencv

双目SLAM(2)  opencv

3 特征点检索

fast特征点

http://www.fengbing.net/2015/07/26/%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%E8%A7%86%E8%A7%89%E9%87%8C%E7%A8%8B%E8%AE%A1%E5%AE%9E%E7%8E%B01/