Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ add_executable(mono_euroc
Examples/Monocular/mono_euroc.cc)
target_link_libraries(mono_euroc ${PROJECT_NAME})

add_executable(mono_kaist
Examples/Monocular/mono_kaist.cc)
target_link_libraries(mono_kaist ${PROJECT_NAME})
57 changes: 57 additions & 0 deletions Examples/Monocular/KAIST-urban18.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
%YAML:1.0

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------

# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 816.9
Camera.fy: 811.6
Camera.cx: 608.5
Camera.cy: 263.5

Camera.k1: -5.6143027800000002e-02
Camera.k2: 1.3952563200000001e-01
Camera.p1: -1.2155906999999999e-03
Camera.p2: -9.7281389999999998e-04

# Camera frames per second
Camera.fps: 10.0

# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 0

#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------

# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 4000

# ORB Extractor: Scale factor between levels in the scale pyramid
ORBextractor.scaleFactor: 1.2

# ORB Extractor: Number of levels in the scale pyramid
ORBextractor.nLevels: 8

# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7

#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500

Binary file added Examples/Monocular/mono_kaist
Binary file not shown.
162 changes: 162 additions & 0 deletions Examples/Monocular/mono_kaist.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* This file is part of ORB-SLAM2.
*
* Copyright (C) 2014-2016 Raúl Mur-Artal <raulmur at unizar dot es> (University of Zaragoza)
* For more information see <https://github.com/raulmur/ORB_SLAM2>
*
* ORB-SLAM2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ORB-SLAM2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ORB-SLAM2. If not, see <http://www.gnu.org/licenses/>.
*/


#include<iostream>
#include<algorithm>
#include<fstream>
#include<chrono>

#include<opencv2/core/core.hpp>

#include"System.h"

using namespace std;

void LoadImages(const string &strSequence, vector<string> &vstrImageFilenames,
vector<double> &vTimestamps);

int main(int argc, char **argv)
{
if(argc != 4)
{
cerr << endl << "Usage: ./mono_kaist path_to_vocabulary path_to_settings path_to_sequence" << endl;
return 1;
}

// Retrieve paths to images
vector<string> vstrImageFilenames;
vector<double> vTimestamps;
LoadImages(string(argv[3]), vstrImageFilenames, vTimestamps);

int nImages = vstrImageFilenames.size();

// Create SLAM system. It initializes all system threads and gets ready to process frames.
ORB_SLAM2::System SLAM(argv[1],argv[2],ORB_SLAM2::System::MONOCULAR,true);

// Vector for tracking time statistics
vector<float> vTimesTrack;
vTimesTrack.resize(nImages);

cout << endl << "-------" << endl;
cout << "Start processing sequence ..." << endl;
cout << "Images in the sequence: " << nImages << endl << endl;

// Main loop
cv::Mat im;
for(int ni=0; ni<nImages; ni++)
{
// Read image from file
im = cv::imread(vstrImageFilenames[ni],CV_LOAD_IMAGE_UNCHANGED);
cv::cvtColor(im, im, cv::COLOR_BayerRG2BGR_EA);

double tframe = vTimestamps[ni];

if(im.empty())
{
cerr << endl << "Failed to load image at: " << vstrImageFilenames[ni] << endl;
return 1;
}

#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
#endif

// Pass the image to the SLAM system
SLAM.TrackMonocular(im,tframe);

#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
#endif

double ttrack= std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();

vTimesTrack[ni]=ttrack;

// Wait to load the next frame
double T=0;
if(ni<nImages-1)
T = vTimestamps[ni+1]-tframe;
else if(ni>0)
T = tframe-vTimestamps[ni-1];

if(ttrack<T)
usleep((T-ttrack)*1e6);
}

// Stop all threads
SLAM.Shutdown();

// Tracking time statistics
sort(vTimesTrack.begin(),vTimesTrack.end());
float totaltime = 0;
for(int ni=0; ni<nImages; ni++)
{
totaltime+=vTimesTrack[ni];
}
cout << "-------" << endl << endl;
cout << "median tracking time: " << vTimesTrack[nImages/2] << endl;
cout << "mean tracking time: " << totaltime/nImages << endl;

// Save camera trajectory
SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt");

return 0;
}

void LoadImages(const string &strPathToSequence, vector<string> &vstrImageFilenames, vector<double> &vTimestamps)
{
ifstream fTimes;
vector<string> stringTimestamps;
string strPathTimeFile = strPathToSequence + "/sensor_data/stereo_stamp.csv";
fTimes.open(strPathTimeFile.c_str());
if (!fTimes) {
cout << "Could not open file with timestamps!" << endl;
return;
}
while(!fTimes.eof())
{
string s;
getline(fTimes,s);
if(!s.empty())
{
stringstream ss;
ss << s;
double t;
ss >> t;
vTimestamps.push_back(t / 10000000000);
stringTimestamps.push_back(s);
}
}

string strPrefixLeft = strPathToSequence + "/image/stereo_left/";

const int nTimes = vTimestamps.size();
vstrImageFilenames.resize(nTimes);

for(int i=0; i<nTimes; i++)
{
vstrImageFilenames[i] = strPrefixLeft + stringTimestamps[i] + ".png";
}
}
7 changes: 4 additions & 3 deletions include/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#ifndef SYSTEM_H
#define SYSTEM_H

#include<string>
#include<thread>
#include<opencv2/core/core.hpp>
#include <string>
#include <thread>
#include <unistd.h>
#include <opencv2/core/core.hpp>

#include "Tracking.h"
#include "FrameDrawer.h"
Expand Down