Skip to content

Commit

Permalink
compile in debian; and created live demo;
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfu committed Jan 23, 2017
1 parent d4c8858 commit be6c247
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ target_link_libraries(stereo_euroc ${PROJECT_NAME})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)

add_executable(mono_live
Examples/Monocular/mono_live.cc)
target_link_libraries(mono_live ${PROJECT_NAME})

add_executable(mono_tum
Examples/Monocular/mono_tum.cc)
target_link_libraries(mono_tum ${PROJECT_NAME})
Expand Down
1 change: 1 addition & 0 deletions Examples/Monocular/mono_euroc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include<algorithm>
#include<fstream>
#include<chrono>
#include <unistd.h>

#include<opencv2/core/core.hpp>

Expand Down
1 change: 1 addition & 0 deletions Examples/Monocular/mono_kitti.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include<fstream>
#include<chrono>
#include<iomanip>
#include <unistd.h>

#include<opencv2/core/core.hpp>

Expand Down
132 changes: 132 additions & 0 deletions Examples/Monocular/mono_live.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* 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 <unistd.h>

#include<opencv2/core/core.hpp>

#include<System.h>

#include <sys/time.h>
double currentTime(){
struct timeval tp;
gettimeofday(&tp, NULL);
long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
return ms/1000.;
}

using namespace std;

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

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

// Retrieve paths to images
vector<string> vstrImageFilenames;
vector<double> vTimestamps;
string strFile = string(argv[3])+"/rgb.txt";
cv::VideoCapture capture;
capture.open(atoi(argv[3]));
if (!capture.isOpened()){fprintf(stderr,"fail to open %s.\n",argv[3]);exit(-1);}

int nImages = 1<<16;

// 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);
vTimestamps.resize(nImages);
for(int ni=0; ni<nImages; ni++){
vTimestamps[ni]=ni*0.03333333;
}

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
capture >> im;
double tframe = vTimestamps[ni];

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

double t1 = currentTime();

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

double t2 = currentTime();
double ttrack = t2-t1;

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;
}
1 change: 1 addition & 0 deletions Examples/Monocular/mono_tum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include<algorithm>
#include<fstream>
#include<chrono>
#include <unistd.h>

#include<opencv2/core/core.hpp>

Expand Down
1 change: 1 addition & 0 deletions Examples/RGB-D/rgbd_tum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include<algorithm>
#include<fstream>
#include<chrono>
#include <unistd.h>

#include<opencv2/core/core.hpp>

Expand Down
1 change: 1 addition & 0 deletions Examples/Stereo/stereo_euroc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include<fstream>
#include<iomanip>
#include<chrono>
#include <unistd.h>

#include<opencv2/core/core.hpp>

Expand Down
1 change: 1 addition & 0 deletions Examples/Stereo/stereo_kitti.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include<fstream>
#include<iomanip>
#include<chrono>
#include <unistd.h>

#include<opencv2/core/core.hpp>

Expand Down
20 changes: 12 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
echo "Configuring and building Thirdparty/DBoW2 ..."
#!/usr/bin/env bash

set -e
set -v

echo "Configuring and building Thirdparty/DBoW2 ..."
cd Thirdparty/DBoW2
mkdir build
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
make -j2

cd ../../g2o

echo "Configuring and building Thirdparty/g2o ..."

mkdir build
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
make -j2

cd ../../../

Expand All @@ -25,7 +29,7 @@ cd ..

echo "Configuring and building ORB_SLAM2 ..."

mkdir build
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j2
1 change: 1 addition & 0 deletions src/LocalMapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Optimizer.h"

#include<mutex>
#include <unistd.h>

namespace ORB_SLAM2
{
Expand Down
2 changes: 1 addition & 1 deletion src/LoopClosing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include<mutex>
#include<thread>

#include <unistd.h>

namespace ORB_SLAM2
{
Expand Down
1 change: 1 addition & 0 deletions src/System.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <thread>
#include <pangolin/pangolin.h>
#include <iomanip>
#include <unistd.h>

namespace ORB_SLAM2
{
Expand Down
1 change: 1 addition & 0 deletions src/Tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include"PnPsolver.h"

#include<iostream>
#include <unistd.h>

#include<mutex>

Expand Down
1 change: 1 addition & 0 deletions src/Viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <pangolin/pangolin.h>

#include <mutex>
#include <unistd.h>

namespace ORB_SLAM2
{
Expand Down

0 comments on commit be6c247

Please sign in to comment.