diff --git a/Examples/Monocular/mono_euroc.cc b/Examples/Monocular/mono_euroc.cc
index 4bcb90f170..ca8d3afe82 100644
--- a/Examples/Monocular/mono_euroc.cc
+++ b/Examples/Monocular/mono_euroc.cc
@@ -18,15 +18,15 @@
* along with ORB-SLAM2. If not, see .
*/
+#include
+#include
+#include
+#include
+#include "unistd.h"
-#include
-#include
-#include
-#include
+#include
-#include
-
-#include
+#include
using namespace std;
@@ -35,9 +35,10 @@ void LoadImages(const string &strImagePath, const string &strPathTimes,
int main(int argc, char **argv)
{
- if(argc != 5)
+ if (argc != 5)
{
- cerr << endl << "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_image_folder path_to_times_file" << endl;
+ cerr << endl
+ << "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_image_folder path_to_times_file" << endl;
return 1;
}
@@ -48,35 +49,38 @@ int main(int argc, char **argv)
int nImages = vstrImageFilenames.size();
- if(nImages<=0)
+ if (nImages <= 0)
{
cerr << "ERROR: Failed to load images" << endl;
return 1;
}
// 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);
+ ORB_SLAM2::System SLAM(argv[1], argv[2], ORB_SLAM2::System::MONOCULAR, true);
// Vector for tracking time statistics
vector vTimesTrack;
vTimesTrack.resize(nImages);
- cout << endl << "-------" << endl;
+ cout << endl
+ << "-------" << endl;
cout << "Start processing sequence ..." << endl;
- cout << "Images in the sequence: " << nImages << endl << endl;
+ cout << "Images in the sequence: " << nImages << endl
+ << endl;
// Main loop
cv::Mat im;
- for(int ni=0; ni >(t2 - t1).count();
+ double ttrack = std::chrono::duration_cast>(t2 - t1).count();
- vTimesTrack[ni]=ttrack;
+ vTimesTrack[ni] = ttrack;
// Wait to load the next frame
- double T=0;
- if(ni0)
- T = tframe-vTimestamps[ni-1];
-
- if(ttrack 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());
+ sort(vTimesTrack.begin(), vTimesTrack.end());
float totaltime = 0;
- for(int ni=0; ni> t;
- vTimeStamps.push_back(t/1e9);
-
+ vTimeStamps.push_back(t / 1e9);
}
}
}
diff --git a/Examples/Monocular/mono_kitti.cc b/Examples/Monocular/mono_kitti.cc
index f2f7b3ebfd..d3368d609b 100644
--- a/Examples/Monocular/mono_kitti.cc
+++ b/Examples/Monocular/mono_kitti.cc
@@ -18,16 +18,16 @@
* along with ORB-SLAM2. If not, see .
*/
+#include
+#include
+#include
+#include
+#include
+#include "unistd.h"
-#include
-#include
-#include
-#include
-#include
+#include
-#include
-
-#include"System.h"
+#include "System.h"
using namespace std;
@@ -36,9 +36,10 @@ void LoadImages(const string &strSequence, vector &vstrImageFilenames,
int main(int argc, char **argv)
{
- if(argc != 4)
+ if (argc != 4)
{
- cerr << endl << "Usage: ./mono_kitti path_to_vocabulary path_to_settings path_to_sequence" << endl;
+ cerr << endl
+ << "Usage: ./mono_kitti path_to_vocabulary path_to_settings path_to_sequence" << endl;
return 1;
}
@@ -50,27 +51,30 @@ int main(int argc, char **argv)
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);
+ ORB_SLAM2::System SLAM(argv[1], argv[2], ORB_SLAM2::System::MONOCULAR, true);
// Vector for tracking time statistics
vector vTimesTrack;
vTimesTrack.resize(nImages);
- cout << endl << "-------" << endl;
+ cout << endl
+ << "-------" << endl;
cout << "Start processing sequence ..." << endl;
- cout << "Images in the sequence: " << nImages << endl << endl;
+ cout << "Images in the sequence: " << nImages << endl
+ << endl;
// Main loop
cv::Mat im;
- for(int ni=0; ni >(t2 - t1).count();
+ double ttrack = std::chrono::duration_cast>(t2 - t1).count();
- vTimesTrack[ni]=ttrack;
+ vTimesTrack[ni] = ttrack;
// Wait to load the next frame
- double T=0;
- if(ni0)
- T = tframe-vTimestamps[ni-1];
-
- if(ttrack 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());
+ sort(vTimesTrack.begin(), vTimesTrack.end());
float totaltime = 0;
- for(int ni=0; ni &vstrImageFilena
ifstream fTimes;
string strPathTimeFile = strPathToSequence + "/times.txt";
fTimes.open(strPathTimeFile.c_str());
- while(!fTimes.eof())
+ while (!fTimes.eof())
{
string s;
- getline(fTimes,s);
- if(!s.empty())
+ getline(fTimes, s);
+ if (!s.empty())
{
stringstream ss;
ss << s;
@@ -148,7 +153,7 @@ void LoadImages(const string &strPathToSequence, vector &vstrImageFilena
const int nTimes = vTimestamps.size();
vstrImageFilenames.resize(nTimes);
- for(int i=0; i.
*/
+#include
+#include
+#include
+#include
+#include "unistd.h"
-#include
-#include
-#include
-#include
+#include
-#include
-
-#include
+#include
using namespace std;
@@ -35,42 +35,46 @@ void LoadImages(const string &strFile, vector &vstrImageFilenames,
int main(int argc, char **argv)
{
- if(argc != 4)
+ if (argc != 4)
{
- cerr << endl << "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_sequence" << endl;
+ cerr << endl
+ << "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_sequence" << endl;
return 1;
}
// Retrieve paths to images
vector vstrImageFilenames;
vector vTimestamps;
- string strFile = string(argv[3])+"/rgb.txt";
+ string strFile = string(argv[3]) + "/rgb.txt";
LoadImages(strFile, 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);
+ ORB_SLAM2::System SLAM(argv[1], argv[2], ORB_SLAM2::System::MONOCULAR, true);
// Vector for tracking time statistics
vector vTimesTrack;
vTimesTrack.resize(nImages);
- cout << endl << "-------" << endl;
+ cout << endl
+ << "-------" << endl;
cout << "Start processing sequence ..." << endl;
- cout << "Images in the sequence: " << nImages << endl << endl;
+ cout << "Images in the sequence: " << nImages << endl
+ << endl;
// Main loop
cv::Mat im;
- for(int ni=0; ni >(t2 - t1).count();
+ double ttrack = std::chrono::duration_cast>(t2 - t1).count();
- vTimesTrack[ni]=ttrack;
+ vTimesTrack[ni] = ttrack;
// Wait to load the next frame
- double T=0;
- if(ni0)
- T = tframe-vTimestamps[ni-1];
-
- if(ttrack 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());
+ sort(vTimesTrack.begin(), vTimesTrack.end());
float totaltime = 0;
- for(int ni=0; ni &vstrImageFilenames, vecto
// skip first three lines
string s0;
- getline(f,s0);
- getline(f,s0);
- getline(f,s0);
+ getline(f, s0);
+ getline(f, s0);
+ getline(f, s0);
- while(!f.eof())
+ while (!f.eof())
{
string s;
- getline(f,s);
- if(!s.empty())
+ getline(f, s);
+ if (!s.empty())
{
stringstream ss;
ss << s;
diff --git a/Examples/RGB-D/rgbd_tum.cc b/Examples/RGB-D/rgbd_tum.cc
index 001199d1aa..fd0aae8527 100644
--- a/Examples/RGB-D/rgbd_tum.cc
+++ b/Examples/RGB-D/rgbd_tum.cc
@@ -18,15 +18,15 @@
* along with ORB-SLAM2. If not, see .
*/
+#include
+#include
+#include
+#include
+#include "unistd.h"
-#include
-#include
-#include
-#include
+#include
-#include
-
-#include
+#include
using namespace std;
@@ -35,9 +35,10 @@ void LoadImages(const string &strAssociationFilename, vector &vstrImageF
int main(int argc, char **argv)
{
- if(argc != 5)
+ if (argc != 5)
{
- cerr << endl << "Usage: ./rgbd_tum path_to_vocabulary path_to_settings path_to_sequence path_to_association" << endl;
+ cerr << endl
+ << "Usage: ./rgbd_tum path_to_vocabulary path_to_settings path_to_sequence path_to_association" << endl;
return 1;
}
@@ -50,40 +51,45 @@ int main(int argc, char **argv)
// Check consistency in the number of images and depthmaps
int nImages = vstrImageFilenamesRGB.size();
- if(vstrImageFilenamesRGB.empty())
+ if (vstrImageFilenamesRGB.empty())
{
- cerr << endl << "No images found in provided path." << endl;
+ cerr << endl
+ << "No images found in provided path." << endl;
return 1;
}
- else if(vstrImageFilenamesD.size()!=vstrImageFilenamesRGB.size())
+ else if (vstrImageFilenamesD.size() != vstrImageFilenamesRGB.size())
{
- cerr << endl << "Different number of images for rgb and depth." << endl;
+ cerr << endl
+ << "Different number of images for rgb and depth." << endl;
return 1;
}
// 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::RGBD,true);
+ ORB_SLAM2::System SLAM(argv[1], argv[2], ORB_SLAM2::System::RGBD, true);
// Vector for tracking time statistics
vector vTimesTrack;
vTimesTrack.resize(nImages);
- cout << endl << "-------" << endl;
+ cout << endl
+ << "-------" << endl;
cout << "Start processing sequence ..." << endl;
- cout << "Images in the sequence: " << nImages << endl << endl;
+ cout << "Images in the sequence: " << nImages << endl
+ << endl;
// Main loop
cv::Mat imRGB, imD;
- for(int ni=0; ni >(t2 - t1).count();
+ double ttrack = std::chrono::duration_cast>(t2 - t1).count();
- vTimesTrack[ni]=ttrack;
+ vTimesTrack[ni] = ttrack;
// Wait to load the next frame
- double T=0;
- if(ni0)
- T = tframe-vTimestamps[ni-1];
-
- if(ttrack 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());
+ sort(vTimesTrack.begin(), vTimesTrack.end());
float totaltime = 0;
- for(int ni=0; ni &vstrImageF
{
ifstream fAssociation;
fAssociation.open(strAssociationFilename.c_str());
- while(!fAssociation.eof())
+ while (!fAssociation.eof())
{
string s;
- getline(fAssociation,s);
- if(!s.empty())
+ getline(fAssociation, s);
+ if (!s.empty())
{
stringstream ss;
ss << s;
@@ -161,7 +168,6 @@ void LoadImages(const string &strAssociationFilename, vector &vstrImageF
ss >> t;
ss >> sD;
vstrImageFilenamesD.push_back(sD);
-
}
}
}
diff --git a/Examples/ROS/ORB_SLAM2/CMakeLists.txt b/Examples/ROS/ORB_SLAM2/CMakeLists.txt
index 7cbf71c199..a003c103bd 100644
--- a/Examples/ROS/ORB_SLAM2/CMakeLists.txt
+++ b/Examples/ROS/ORB_SLAM2/CMakeLists.txt
@@ -48,13 +48,14 @@ ${PROJECT_SOURCE_DIR}/../../../include
${Pangolin_INCLUDE_DIRS}
)
-set(LIBS
-${OpenCV_LIBS}
+set(LIBS
+${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
+-lboost_system
)
# Node for monocular camera
diff --git a/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc b/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc
index 9c548e87d1..721c739a61 100644
--- a/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc
+++ b/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc
@@ -25,6 +25,7 @@
#include
#include
#include
+#include "unistd.h"
using namespace std;
@@ -35,38 +36,38 @@ const float eps = 1e-4;
cv::Mat ExpSO3(const float &x, const float &y, const float &z)
{
- cv::Mat I = cv::Mat::eye(3,3,CV_32F);
- const float d2 = x*x+y*y+z*z;
+ cv::Mat I = cv::Mat::eye(3, 3, CV_32F);
+ const float d2 = x * x + y * y + z * z;
const float d = sqrt(d2);
- cv::Mat W = (cv::Mat_(3,3) << 0, -z, y,
+ cv::Mat W = (cv::Mat_(3, 3) << 0, -z, y,
z, 0, -x,
- -y, x, 0);
- if(d(0),v.at(1),v.at(2));
+ return ExpSO3(v.at(0), v.at(1), v.at(2));
}
-ViewerAR::ViewerAR(){}
+ViewerAR::ViewerAR() {}
void ViewerAR::Run()
{
- int w,h,wui;
+ int w, h, wui;
cv::Mat im, Tcw;
int status;
vector vKeys;
- vector vMPs;
+ vector vMPs;
- while(1)
+ while (1)
{
- GetImagePose(im,Tcw,status,vKeys,vMPs);
- if(im.empty())
+ GetImagePose(im, Tcw, status, vKeys, vMPs);
+ if (im.empty())
cv::waitKey(mT);
else
{
@@ -76,46 +77,46 @@ void ViewerAR::Run()
}
}
- wui=200;
+ wui = 200;
- pangolin::CreateWindowAndBind("Viewer",w+wui,h);
+ pangolin::CreateWindowAndBind("Viewer", w + wui, h);
glEnable(GL_DEPTH_TEST);
- glEnable (GL_BLEND);
-
- pangolin::CreatePanel("menu").SetBounds(0.0,1.0,0.0,pangolin::Attach::Pix(wui));
- pangolin::Var menu_detectplane("menu.Insert Cube",false,false);
- pangolin::Var menu_clear("menu.Clear All",false,false);
- pangolin::Var menu_drawim("menu.Draw Image",true,true);
- pangolin::Var menu_drawcube("menu.Draw Cube",true,true);
- pangolin::Var menu_cubesize("menu. Cube Size",0.05,0.01,0.3);
- pangolin::Var menu_drawgrid("menu.Draw Grid",true,true);
- pangolin::Var menu_ngrid("menu. Grid Elements",3,1,10);
- pangolin::Var menu_sizegrid("menu. Element Size",0.05,0.01,0.3);
- pangolin::Var menu_drawpoints("menu.Draw Points",false,true);
-
- pangolin::Var menu_LocalizationMode("menu.Localization Mode",false,true);
+ glEnable(GL_BLEND);
+
+ pangolin::CreatePanel("menu").SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(wui));
+ pangolin::Var menu_detectplane("menu.Insert Cube", false, false);
+ pangolin::Var menu_clear("menu.Clear All", false, false);
+ pangolin::Var menu_drawim("menu.Draw Image", true, true);
+ pangolin::Var menu_drawcube("menu.Draw Cube", true, true);
+ pangolin::Var menu_cubesize("menu. Cube Size", 0.05, 0.01, 0.3);
+ pangolin::Var menu_drawgrid("menu.Draw Grid", true, true);
+ pangolin::Var menu_ngrid("menu. Grid Elements", 3, 1, 10);
+ pangolin::Var menu_sizegrid("menu. Element Size", 0.05, 0.01, 0.3);
+ pangolin::Var menu_drawpoints("menu.Draw Points", false, true);
+
+ pangolin::Var menu_LocalizationMode("menu.Localization Mode", false, true);
bool bLocalizationMode = false;
- pangolin::View& d_image = pangolin::Display("image")
- .SetBounds(0,1.0f,pangolin::Attach::Pix(wui),1.0f,(float)w/h)
- .SetLock(pangolin::LockLeft, pangolin::LockTop);
+ pangolin::View &d_image = pangolin::Display("image")
+ .SetBounds(0, 1.0f, pangolin::Attach::Pix(wui), 1.0f, (float)w / h)
+ .SetLock(pangolin::LockLeft, pangolin::LockTop);
- pangolin::GlTexture imageTexture(w,h,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
+ pangolin::GlTexture imageTexture(w, h, GL_RGB, false, 0, GL_RGB, GL_UNSIGNED_BYTE);
- pangolin::OpenGlMatrixSpec P = pangolin::ProjectionMatrixRDF_TopLeft(w,h,fx,fy,cx,cy,0.001,1000);
+ pangolin::OpenGlMatrixSpec P = pangolin::ProjectionMatrixRDF_TopLeft(w, h, fx, fy, cx, cy, 0.001, 1000);
- vector vpPlane;
+ vector vpPlane;
- while(1)
+ while (1)
{
- if(menu_LocalizationMode && !bLocalizationMode)
+ if (menu_LocalizationMode && !bLocalizationMode)
{
mpSystem->ActivateLocalizationMode();
bLocalizationMode = true;
}
- else if(!menu_LocalizationMode && bLocalizationMode)
+ else if (!menu_LocalizationMode && bLocalizationMode)
{
mpSystem->DeactivateLocalizationMode();
bLocalizationMode = false;
@@ -125,20 +126,20 @@ void ViewerAR::Run()
// Activate camera view
d_image.Activate();
- glColor3f(1.0,1.0,1.0);
+ glColor3f(1.0, 1.0, 1.0);
// Get last image and its computed pose from SLAM
- GetImagePose(im,Tcw,status,vKeys,vMPs);
+ GetImagePose(im, Tcw, status, vKeys, vMPs);
// Add text to image
- PrintStatus(status,bLocalizationMode,im);
+ PrintStatus(status, bLocalizationMode, im);
- if(menu_drawpoints)
- DrawTrackedPoints(vKeys,vMPs,im);
+ if (menu_drawpoints)
+ DrawTrackedPoints(vKeys, vMPs, im);
// Draw image
- if(menu_drawim)
- DrawImageTexture(imageTexture,im);
+ if (menu_drawim)
+ DrawImageTexture(imageTexture, im);
glClear(GL_DEPTH_BUFFER_BIT);
@@ -152,13 +153,13 @@ void ViewerAR::Run()
LoadCameraPose(Tcw);
// Draw virtual things
- if(status==2)
+ if (status == 2)
{
- if(menu_clear)
+ if (menu_clear)
{
- if(!vpPlane.empty())
+ if (!vpPlane.empty())
{
- for(size_t i=0; iMapChanged())
+ if (mpSystem->MapChanged())
{
cout << "Map changed. All virtual elements are recomputed!" << endl;
bRecompute = true;
}
}
- for(size_t i=0; iRecompute();
}
@@ -210,32 +211,29 @@ void ViewerAR::Run()
pPlane->glTpw.Multiply();
// Draw cube
- if(menu_drawcube)
+ if (menu_drawcube)
{
DrawCube(menu_cubesize);
}
// Draw grid plane
- if(menu_drawgrid)
+ if (menu_drawgrid)
{
- DrawPlane(menu_ngrid,menu_sizegrid);
+ DrawPlane(menu_ngrid, menu_sizegrid);
}
glPopMatrix();
}
}
}
-
-
}
pangolin::FinishFrame();
- usleep(mT*1000);
+ usleep(mT * 1000);
}
-
}
-void ViewerAR::SetImagePose(const cv::Mat &im, const cv::Mat &Tcw, const int &status, const vector &vKeys, const vector &vMPs)
+void ViewerAR::SetImagePose(const cv::Mat &im, const cv::Mat &Tcw, const int &status, const vector &vKeys, const vector &vMPs)
{
unique_lock lock(mMutexPoseImage);
mImage = im.clone();
@@ -245,7 +243,7 @@ void ViewerAR::SetImagePose(const cv::Mat &im, const cv::Mat &Tcw, const int &st
mvMPs = vMPs;
}
-void ViewerAR::GetImagePose(cv::Mat &im, cv::Mat &Tcw, int &status, std::vector &vKeys, std::vector &vMPs)
+void ViewerAR::GetImagePose(cv::Mat &im, cv::Mat &Tcw, int &status, std::vector &vKeys, std::vector &vMPs)
{
unique_lock lock(mMutexPoseImage);
im = mImage.clone();
@@ -257,29 +255,29 @@ void ViewerAR::GetImagePose(cv::Mat &im, cv::Mat &Tcw, int &status, std::vector<
void ViewerAR::LoadCameraPose(const cv::Mat &Tcw)
{
- if(!Tcw.empty())
+ if (!Tcw.empty())
{
pangolin::OpenGlMatrix M;
- M.m[0] = Tcw.at(0,0);
- M.m[1] = Tcw.at(1,0);
- M.m[2] = Tcw.at(2,0);
- M.m[3] = 0.0;
+ M.m[0] = Tcw.at(0, 0);
+ M.m[1] = Tcw.at(1, 0);
+ M.m[2] = Tcw.at(2, 0);
+ M.m[3] = 0.0;
- M.m[4] = Tcw.at(0,1);
- M.m[5] = Tcw.at(1,1);
- M.m[6] = Tcw.at(2,1);
- M.m[7] = 0.0;
+ M.m[4] = Tcw.at(0, 1);
+ M.m[5] = Tcw.at(1, 1);
+ M.m[6] = Tcw.at(2, 1);
+ M.m[7] = 0.0;
- M.m[8] = Tcw.at(0,2);
- M.m[9] = Tcw.at(1,2);
- M.m[10] = Tcw.at(2,2);
- M.m[11] = 0.0;
+ M.m[8] = Tcw.at(0, 2);
+ M.m[9] = Tcw.at(1, 2);
+ M.m[10] = Tcw.at(2, 2);
+ M.m[11] = 0.0;
- M.m[12] = Tcw.at(0,3);
- M.m[13] = Tcw.at(1,3);
- M.m[14] = Tcw.at(2,3);
- M.m[15] = 1.0;
+ M.m[12] = Tcw.at(0, 3);
+ M.m[13] = Tcw.at(1, 3);
+ M.m[14] = Tcw.at(2, 3);
+ M.m[15] = 1.0;
M.Load();
}
@@ -287,22 +285,46 @@ void ViewerAR::LoadCameraPose(const cv::Mat &Tcw)
void ViewerAR::PrintStatus(const int &status, const bool &bLocMode, cv::Mat &im)
{
- if(!bLocMode)
+ if (!bLocMode)
{
- switch(status)
+ switch (status)
{
- case 1: {AddTextToImage("SLAM NOT INITIALIZED",im,255,0,0); break;}
- case 2: {AddTextToImage("SLAM ON",im,0,255,0); break;}
- case 3: {AddTextToImage("SLAM LOST",im,255,0,0); break;}
+ case 1:
+ {
+ AddTextToImage("SLAM NOT INITIALIZED", im, 255, 0, 0);
+ break;
+ }
+ case 2:
+ {
+ AddTextToImage("SLAM ON", im, 0, 255, 0);
+ break;
+ }
+ case 3:
+ {
+ AddTextToImage("SLAM LOST", im, 255, 0, 0);
+ break;
+ }
}
}
else
{
- switch(status)
+ switch (status)
+ {
+ case 1:
{
- case 1: {AddTextToImage("SLAM NOT INITIALIZED",im,255,0,0); break;}
- case 2: {AddTextToImage("LOCALIZATION ON",im,0,255,0); break;}
- case 3: {AddTextToImage("LOCALIZATION LOST",im,255,0,0); break;}
+ AddTextToImage("SLAM NOT INITIALIZED", im, 255, 0, 0);
+ break;
+ }
+ case 2:
+ {
+ AddTextToImage("LOCALIZATION ON", im, 0, 255, 0);
+ break;
+ }
+ case 3:
+ {
+ AddTextToImage("LOCALIZATION LOST", im, 255, 0, 0);
+ break;
+ }
}
}
}
@@ -311,34 +333,34 @@ void ViewerAR::AddTextToImage(const string &s, cv::Mat &im, const int r, const i
{
int l = 10;
//imText.rowRange(im.rows-imText.rows,imText.rows) = cv::Mat::zeros(textSize.height+10,im.cols,im.type());
- cv::putText(im,s,cv::Point(l,im.rows-l),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l-1,im.rows-l),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l+1,im.rows-l),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l-1,im.rows-(l-1)),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l,im.rows-(l-1)),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l+1,im.rows-(l-1)),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l-1,im.rows-(l+1)),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l,im.rows-(l+1)),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
- cv::putText(im,s,cv::Point(l+1,im.rows-(l+1)),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(255,255,255),2,8);
-
- cv::putText(im,s,cv::Point(l,im.rows-l),cv::FONT_HERSHEY_PLAIN,1.5,cv::Scalar(r,g,b),2,8);
+ cv::putText(im, s, cv::Point(l, im.rows - l), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l - 1, im.rows - l), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l + 1, im.rows - l), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l - 1, im.rows - (l - 1)), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l, im.rows - (l - 1)), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l + 1, im.rows - (l - 1)), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l - 1, im.rows - (l + 1)), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l, im.rows - (l + 1)), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+ cv::putText(im, s, cv::Point(l + 1, im.rows - (l + 1)), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 255), 2, 8);
+
+ cv::putText(im, s, cv::Point(l, im.rows - l), cv::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(r, g, b), 2, 8);
}
void ViewerAR::DrawImageTexture(pangolin::GlTexture &imageTexture, cv::Mat &im)
{
- if(!im.empty())
+ if (!im.empty())
{
- imageTexture.Upload(im.data,GL_RGB,GL_UNSIGNED_BYTE);
+ imageTexture.Upload(im.data, GL_RGB, GL_UNSIGNED_BYTE);
imageTexture.RenderToViewportFlipY();
}
}
-void ViewerAR::DrawCube(const float &size,const float x, const float y, const float z)
+void ViewerAR::DrawCube(const float &size, const float x, const float y, const float z)
{
- pangolin::OpenGlMatrix M = pangolin::OpenGlMatrix::Translate(-x,-size-y,-z);
+ pangolin::OpenGlMatrix M = pangolin::OpenGlMatrix::Translate(-x, -size - y, -z);
glPushMatrix();
M.Multiply();
- pangolin::glDrawColouredCube(-size,size);
+ pangolin::glDrawColouredCube(-size, size);
glPopMatrix();
}
@@ -346,63 +368,60 @@ void ViewerAR::DrawPlane(Plane *pPlane, int ndivs, float ndivsize)
{
glPushMatrix();
pPlane->glTpw.Multiply();
- DrawPlane(ndivs,ndivsize);
+ DrawPlane(ndivs, ndivsize);
glPopMatrix();
}
void ViewerAR::DrawPlane(int ndivs, float ndivsize)
{
// Plane parallel to x-z at origin with normal -y
- const float minx = -ndivs*ndivsize;
- const float minz = -ndivs*ndivsize;
- const float maxx = ndivs*ndivsize;
- const float maxz = ndivs*ndivsize;
-
+ const float minx = -ndivs * ndivsize;
+ const float minz = -ndivs * ndivsize;
+ const float maxx = ndivs * ndivsize;
+ const float maxz = ndivs * ndivsize;
glLineWidth(2);
- glColor3f(0.7f,0.7f,1.0f);
+ glColor3f(0.7f, 0.7f, 1.0f);
glBegin(GL_LINES);
- for(int n = 0; n<=2*ndivs; n++)
+ for (int n = 0; n <= 2 * ndivs; n++)
{
- glVertex3f(minx+ndivsize*n,0,minz);
- glVertex3f(minx+ndivsize*n,0,maxz);
- glVertex3f(minx,0,minz+ndivsize*n);
- glVertex3f(maxx,0,minz+ndivsize*n);
+ glVertex3f(minx + ndivsize * n, 0, minz);
+ glVertex3f(minx + ndivsize * n, 0, maxz);
+ glVertex3f(minx, 0, minz + ndivsize * n);
+ glVertex3f(maxx, 0, minz + ndivsize * n);
}
glEnd();
-
}
void ViewerAR::DrawTrackedPoints(const std::vector &vKeys, const std::vector &vMPs, cv::Mat &im)
{
const int N = vKeys.size();
-
- for(int i=0; i &vMPs, const int iterations)
+Plane *ViewerAR::DetectPlane(const cv::Mat Tcw, const std::vector &vMPs, const int iterations)
{
// Retrieve 3D points
vector vPoints;
vPoints.reserve(vMPs.size());
- vector vPointMP;
+ vector vPointMP;
vPointMP.reserve(vMPs.size());
- for(size_t i=0; iObservations()>5)
+ if (pMP->Observations() > 5)
{
vPoints.push_back(pMP->GetWorldPos());
vPointMP.push_back(pMP);
@@ -412,16 +431,15 @@ Plane* ViewerAR::DetectPlane(const cv::Mat Tcw, const std::vector &vM
const int N = vPoints.size();
- if(N<50)
+ if (N < 50)
return NULL;
-
// Indices for minimum set selection
vector vAllIndices;
vAllIndices.reserve(N);
vector vAvailableIndices;
- for(int i=0; i &vM
vector bestvDist;
//RANSAC
- for(int n=0; n(3,0);
- const float b = vt.at(3,1);
- const float c = vt.at(3,2);
- const float d = vt.at(3,3);
+ const float a = vt.at(3, 0);
+ const float b = vt.at(3, 1);
+ const float c = vt.at(3, 2);
+ const float d = vt.at(3, 3);
- vector vDistances(N,0);
+ vector vDistances(N, 0);
- const float f = 1.0f/sqrt(a*a+b*b+c*c+d*d);
+ const float f = 1.0f / sqrt(a * a + b * b + c * c + d * d);
- for(int i=0; i(0)*a+vPoints[i].at(1)*b+vPoints[i].at(2)*c+d)*f;
+ vDistances[i] = fabs(vPoints[i].at(0) * a + vPoints[i].at(1) * b + vPoints[i].at(2) * c + d) * f;
}
vector vSorted = vDistances;
- sort(vSorted.begin(),vSorted.end());
+ sort(vSorted.begin(), vSorted.end());
- int nth = max((int)(0.2*N),20);
+ int nth = max((int)(0.2 * N), 20);
const float medianDist = vSorted[nth];
- if(medianDist &vM
}
// Compute threshold inlier/outlier
- const float th = 1.4*bestDist;
- vector vbInliers(N,false);
+ const float th = 1.4 * bestDist;
+ vector vbInliers(N, false);
int nInliers = 0;
- for(int i=0; i vInlierMPs(nInliers,NULL);
+ vector vInlierMPs(nInliers, NULL);
int nin = 0;
- for(int i=0; i &vMPs, const cv::Mat &Tcw):mvMPs(vMPs),mTcw(Tcw.clone())
+Plane::Plane(const std::vector &vMPs, const cv::Mat &Tcw) : mvMPs(vMPs), mTcw(Tcw.clone())
{
- rang = -3.14f/2+((float)rand()/RAND_MAX)*3.14f;
+ rang = -3.14f / 2 + ((float)rand() / RAND_MAX) * 3.14f;
Recompute();
}
@@ -518,125 +536,123 @@ void Plane::Recompute()
const int N = mvMPs.size();
// Recompute plane with all points
- cv::Mat A = cv::Mat(N,4,CV_32F);
- A.col(3) = cv::Mat::ones(N,1,CV_32F);
+ cv::Mat A = cv::Mat(N, 4, CV_32F);
+ A.col(3) = cv::Mat::ones(N, 1, CV_32F);
- o = cv::Mat::zeros(3,1,CV_32F);
+ o = cv::Mat::zeros(3, 1, CV_32F);
int nPoints = 0;
- for(int i=0; iisBad())
+ MapPoint *pMP = mvMPs[i];
+ if (!pMP->isBad())
{
cv::Mat Xw = pMP->GetWorldPos();
- o+=Xw;
- A.row(nPoints).colRange(0,3) = Xw.t();
+ o += Xw;
+ A.row(nPoints).colRange(0, 3) = Xw.t();
nPoints++;
}
}
A.resize(nPoints);
- cv::Mat u,w,vt;
- cv::SVDecomp(A,w,u,vt,cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
+ cv::Mat u, w, vt;
+ cv::SVDecomp(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
- float a = vt.at(3,0);
- float b = vt.at(3,1);
- float c = vt.at(3,2);
+ float a = vt.at(3, 0);
+ float b = vt.at(3, 1);
+ float c = vt.at(3, 2);
- o = o*(1.0f/nPoints);
- const float f = 1.0f/sqrt(a*a+b*b+c*c);
+ o = o * (1.0f / nPoints);
+ const float f = 1.0f / sqrt(a * a + b * b + c * c);
// Compute XC just the first time
- if(XC.empty())
+ if (XC.empty())
{
- cv::Mat Oc = -mTcw.colRange(0,3).rowRange(0,3).t()*mTcw.rowRange(0,3).col(3);
- XC = Oc-o;
+ cv::Mat Oc = -mTcw.colRange(0, 3).rowRange(0, 3).t() * mTcw.rowRange(0, 3).col(3);
+ XC = Oc - o;
}
- if((XC.at(0)*a+XC.at(1)*b+XC.at(2)*c)>0)
+ if ((XC.at(0) * a + XC.at(1) * b + XC.at(2) * c) > 0)
{
- a=-a;
- b=-b;
- c=-c;
+ a = -a;
+ b = -b;
+ c = -c;
}
- const float nx = a*f;
- const float ny = b*f;
- const float nz = c*f;
+ const float nx = a * f;
+ const float ny = b * f;
+ const float nz = c * f;
- n = (cv::Mat_(3,1)<(3, 1) << nx, ny, nz);
- cv::Mat up = (cv::Mat_(3,1) << 0.0f, 1.0f, 0.0f);
+ cv::Mat up = (cv::Mat_(3, 1) << 0.0f, 1.0f, 0.0f);
cv::Mat v = up.cross(n);
const float sa = cv::norm(v);
const float ca = up.dot(n);
- const float ang = atan2(sa,ca);
- Tpw = cv::Mat::eye(4,4,CV_32F);
-
-
- Tpw.rowRange(0,3).colRange(0,3) = ExpSO3(v*ang/sa)*ExpSO3(up*rang);
- o.copyTo(Tpw.col(3).rowRange(0,3));
-
- glTpw.m[0] = Tpw.at(0,0);
- glTpw.m[1] = Tpw.at(1,0);
- glTpw.m[2] = Tpw.at(2,0);
- glTpw.m[3] = 0.0;
-
- glTpw.m[4] = Tpw.at(0,1);
- glTpw.m[5] = Tpw.at(1,1);
- glTpw.m[6] = Tpw.at(2,1);
- glTpw.m[7] = 0.0;
-
- glTpw.m[8] = Tpw.at(0,2);
- glTpw.m[9] = Tpw.at(1,2);
- glTpw.m[10] = Tpw.at(2,2);
- glTpw.m[11] = 0.0;
-
- glTpw.m[12] = Tpw.at(0,3);
- glTpw.m[13] = Tpw.at(1,3);
- glTpw.m[14] = Tpw.at(2,3);
- glTpw.m[15] = 1.0;
-
+ const float ang = atan2(sa, ca);
+ Tpw = cv::Mat::eye(4, 4, CV_32F);
+
+ Tpw.rowRange(0, 3).colRange(0, 3) = ExpSO3(v * ang / sa) * ExpSO3(up * rang);
+ o.copyTo(Tpw.col(3).rowRange(0, 3));
+
+ glTpw.m[0] = Tpw.at(0, 0);
+ glTpw.m[1] = Tpw.at(1, 0);
+ glTpw.m[2] = Tpw.at(2, 0);
+ glTpw.m[3] = 0.0;
+
+ glTpw.m[4] = Tpw.at(0, 1);
+ glTpw.m[5] = Tpw.at(1, 1);
+ glTpw.m[6] = Tpw.at(2, 1);
+ glTpw.m[7] = 0.0;
+
+ glTpw.m[8] = Tpw.at(0, 2);
+ glTpw.m[9] = Tpw.at(1, 2);
+ glTpw.m[10] = Tpw.at(2, 2);
+ glTpw.m[11] = 0.0;
+
+ glTpw.m[12] = Tpw.at(0, 3);
+ glTpw.m[13] = Tpw.at(1, 3);
+ glTpw.m[14] = Tpw.at(2, 3);
+ glTpw.m[15] = 1.0;
}
Plane::Plane(const float &nx, const float &ny, const float &nz, const float &ox, const float &oy, const float &oz)
{
- n = (cv::Mat_(3,1)<(3,1)<(3, 1) << nx, ny, nz);
+ o = (cv::Mat_(3, 1) << ox, oy, oz);
- cv::Mat up = (cv::Mat_(3,1) << 0.0f, 1.0f, 0.0f);
+ cv::Mat up = (cv::Mat_(3, 1) << 0.0f, 1.0f, 0.0f);
cv::Mat v = up.cross(n);
const float s = cv::norm(v);
const float c = up.dot(n);
- const float a = atan2(s,c);
- Tpw = cv::Mat::eye(4,4,CV_32F);
- const float rang = -3.14f/2+((float)rand()/RAND_MAX)*3.14f;
+ const float a = atan2(s, c);
+ Tpw = cv::Mat::eye(4, 4, CV_32F);
+ const float rang = -3.14f / 2 + ((float)rand() / RAND_MAX) * 3.14f;
cout << rang;
- Tpw.rowRange(0,3).colRange(0,3) = ExpSO3(v*a/s)*ExpSO3(up*rang);
- o.copyTo(Tpw.col(3).rowRange(0,3));
-
- glTpw.m[0] = Tpw.at(0,0);
- glTpw.m[1] = Tpw.at(1,0);
- glTpw.m[2] = Tpw.at(2,0);
- glTpw.m[3] = 0.0;
-
- glTpw.m[4] = Tpw.at(0,1);
- glTpw.m[5] = Tpw.at(1,1);
- glTpw.m[6] = Tpw.at(2,1);
- glTpw.m[7] = 0.0;
-
- glTpw.m[8] = Tpw.at(0,2);
- glTpw.m[9] = Tpw.at(1,2);
- glTpw.m[10] = Tpw.at(2,2);
- glTpw.m[11] = 0.0;
-
- glTpw.m[12] = Tpw.at(0,3);
- glTpw.m[13] = Tpw.at(1,3);
- glTpw.m[14] = Tpw.at(2,3);
- glTpw.m[15] = 1.0;
+ Tpw.rowRange(0, 3).colRange(0, 3) = ExpSO3(v * a / s) * ExpSO3(up * rang);
+ o.copyTo(Tpw.col(3).rowRange(0, 3));
+
+ glTpw.m[0] = Tpw.at(0, 0);
+ glTpw.m[1] = Tpw.at(1, 0);
+ glTpw.m[2] = Tpw.at(2, 0);
+ glTpw.m[3] = 0.0;
+
+ glTpw.m[4] = Tpw.at(0, 1);
+ glTpw.m[5] = Tpw.at(1, 1);
+ glTpw.m[6] = Tpw.at(2, 1);
+ glTpw.m[7] = 0.0;
+
+ glTpw.m[8] = Tpw.at(0, 2);
+ glTpw.m[9] = Tpw.at