Skip to content

Commit 0c5f06b

Browse files
author
nils-hamel
committed
Adding group option for structures exportation - moving motion detection function in utiles module - removing stilldetect module - correction in utiles
1 parent 3b3b893 commit 0c5f06b

9 files changed

+84
-89
lines changed

src/framework-database.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,11 @@ void Database::filterDisparity(int pipeState){
622622

623623
}
624624

625-
void Database::exportStructure(std::string path, std::string mode, unsigned int major){
625+
//
626+
// Section - Exportation methods
627+
//
628+
629+
void Database::exportStructure(std::string path, std::string mode, unsigned int major, unsigned int group){
626630
std::fstream exportStream;
627631
std::stringstream filePath;
628632
std::stringstream fileCopy;
@@ -636,16 +640,20 @@ void Database::exportStructure(std::string path, std::string mode, unsigned int
636640
return;
637641
}
638642

639-
for(auto & element: structures){
640-
exportStream << (*element->getPosition())(0) << " ";
641-
exportStream << (*element->getPosition())(1) << " ";
642-
exportStream << (*element->getPosition())(2) << " ";
643+
for(auto & structure: structures){
644+
if(structure->getHasScale(group)){
645+
646+
exportStream << (*structure->getPosition())(0) << " ";
647+
exportStream << (*structure->getPosition())(1) << " ";
648+
exportStream << (*structure->getPosition())(2) << " ";
643649

644-
color=element->getColor();
650+
color=structure->getColor();
645651

646-
exportStream << std::to_string( color[2] ) << " ";
647-
exportStream << std::to_string( color[1] ) << " ";
648-
exportStream << std::to_string( color[0] ) << std::endl;
652+
exportStream << std::to_string( color[2] ) << " ";
653+
exportStream << std::to_string( color[1] ) << " ";
654+
exportStream << std::to_string( color[0] ) << std::endl;
655+
656+
}
649657
}
650658

651659
exportStream.close();
@@ -717,7 +725,7 @@ void Database::exportTransformation(std::string path, std::string mode, unsigned
717725
}
718726

719727
//
720-
// development related features
728+
// Section - Development features - Will be removed
721729
//
722730

723731
// Note : this function does not respect encapsulation (development function) - need to be removed

src/framework-database.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Database {
105105
void computeDisparityStatistics(int loopState);
106106
void filterRadialRange(int loopState);
107107
void filterDisparity(int loopState);
108-
void exportStructure(std::string path, std::string mode, unsigned int major);
108+
void exportStructure(std::string path, std::string mode, unsigned int major, unsigned int group);
109109
void exportPosition(std::string path, std::string mode, unsigned int major);
110110
void exportTransformation(std::string path, std::string mode, unsigned int major);
111111
Structure *newStructure(){ auto s = std::make_shared<Structure>(); structures.push_back(s); return s.get();}

src/framework-frontend.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include "framework-frontend.hpp"
2-
3-
#include "framework-stillcompute.hpp"
42
#include "framework-sparsefeature.hpp"
53
#include "framework-utiles.hpp"
64

@@ -45,7 +43,7 @@ bool FrontendPicture::next() {
4543
lastViewpoint->getImage()->size(),
4644
&lastViewpointMatches
4745
);
48-
double score = computeStillDistance(
46+
double score = utilesDetectMotion(
4947
newViewpoint->getCvFeatures(),
5048
lastViewpoint->getCvFeatures(),
5149
&lastViewpointMatches,

src/framework-stillcompute.cpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/framework-stillcompute.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/framework-utiles.cpp

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
Eigen::Vector3d utiles_direction(double x, double y, int width, int height){
2525

2626
// Convert pixel coordinates to geographic mapping coordinates
27-
double lamda( (x/width) * 2.* M_PI );
28-
double phi ( ((y/(height-1)) - 0.5) * M_PI );
27+
double lamda((x/width)*2.*M_PI);
28+
double phi(((y/(height-1))-0.5)*M_PI);
29+
30+
// Precompute cosine value
31+
double cosine(cos(phi));
2932

3033
// Compute and return direction vector
31-
return Eigen::Vector3d(cos(phi)*cos(lamda), cos(phi)*sin(lamda), sin(phi));
34+
return Eigen::Vector3d(cosine*cos(lamda),cosine*sin(lamda),sin(phi));
3235

3336
}
3437

@@ -51,24 +54,25 @@ void profile(std::string msg){
5154
msgLast = msg;
5255
}
5356

57+
/* delete */
5458
std::mutex exitMutex;
5559
int exitCounter = 0;
5660

61+
/* delete */
5762
void exitRetain(){
5863
exitMutex.lock();
5964
exitCounter++;
6065
exitMutex.unlock();
6166
}
6267

63-
68+
/* delete */
6469
void exitRelease(){
6570
exitMutex.lock();
6671
exitCounter--;
6772
if(exitCounter <= 0) exit(0);
6873
exitMutex.unlock();
6974
}
7075

71-
7276
double bilinear_sample(double *p, double x, double y, int width){
7377
int ix = x;
7478
int iy = y;
@@ -122,3 +126,52 @@ void utiles_directories( std::string rootPath, std::string modeName ) {
122126

123127
}
124128

129+
double utilesDetectMotion(std::vector<cv::KeyPoint> *kp1, std::vector<cv::KeyPoint> *kp2, std::vector<cv::DMatch> *matches, cv::Size size) {
130+
131+
// Vector containing the distances for each pair of features
132+
std::vector<double> vec_dist {};
133+
134+
// loop over the vector of matches
135+
for (const auto &m : *matches) {
136+
137+
auto width = size.width;
138+
auto height = size.height;
139+
140+
// m.queryIdx is the index of the Keypoints on the first image
141+
// m.trainIdx is the index of the Keypoints on the second image
142+
143+
// Convert cartesian to spherical
144+
// Spherical coordinate of the feature on the first image
145+
Eigen::Vector3d p1 = utiles_direction(static_cast<double>((*kp1)[m.queryIdx].pt.x), static_cast<double>((*kp1)[m.queryIdx].pt.y), width, height);
146+
// Spherical coordinate of the feature on the second image
147+
Eigen::Vector3d p2 = utiles_direction(static_cast<double>((*kp2)[m.trainIdx].pt.x), static_cast<double>((*kp2)[m.trainIdx].pt.y), width, height);
148+
149+
// p1*p2 computes the dot product between p1 and p2
150+
// push it to vector of distances
151+
vec_dist.push_back(acos(p1.dot(p2)));
152+
153+
}
154+
155+
// calculation of the mean value
156+
double m { std::accumulate(vec_dist.begin(), vec_dist.end(), 0.0) / vec_dist.size() };
157+
158+
// calculation of variance
159+
double var { 0.0 };
160+
for (const auto & val : vec_dist) {
161+
var += pow(val - m, 2);
162+
}
163+
164+
// check error to avoid division by 0
165+
if (vec_dist.size() <= 1) {
166+
throw(std::runtime_error("Number of features is less or equal to 1"));
167+
}
168+
var /= (vec_dist.size() - 1);
169+
170+
// calculation of std
171+
double vec_std = sqrt(var);
172+
173+
// return mean * std
174+
return m * vec_std;
175+
176+
}
177+

src/framework-utiles.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
// External includes
2525
#include <Eigen/Core>
26+
#include <cmath>
2627
#include <string>
2728
#include <time.h>
2829
#include <iostream>
@@ -33,6 +34,8 @@
3334
#include <experimental/filesystem>
3435
#include <sstream>
3536
#include <iomanip>
37+
#include <opencv4/opencv2/core.hpp>
38+
#include <opencv4/opencv2/core/types.hpp>
3639

3740
// Namespaces
3841
namespace fs = std::experimental::filesystem;
@@ -126,3 +129,5 @@ double bilinear_sample(float *p, double x, double y, int width);
126129

127130
void utiles_directories( std::string rootPath, std::string modeName );
128131

132+
double utilesDetectMotion(std::vector<cv::KeyPoint> *kp1, std::vector<cv::KeyPoint> *kp2, std::vector<cv::DMatch> *matches, cv::Size size);
133+

src/framework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ int main(int argc, char ** argv){
287287
}
288288

289289
// Major iteration exportation : model, odometry and transformation
290-
database.exportStructure (yamlExport["path"].as<std::string>(),yamlFrontend["type"].as<std::string>(),loopMajor);
290+
database.exportStructure (yamlExport["path"].as<std::string>(),yamlFrontend["type"].as<std::string>(),loopMajor,yamlExport["group"].as<unsigned int>());
291291
database.exportPosition (yamlExport["path"].as<std::string>(),yamlFrontend["type"].as<std::string>(),loopMajor);
292292
database.exportTransformation(yamlExport["path"].as<std::string>(),yamlFrontend["type"].as<std::string>(),loopMajor);
293293

src/framework.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
#include "framework-database.hpp"
3333
#include "framework-viewpointsource.hpp"
3434
#include "framework-sparsefeature.hpp"
35-
#include "framework-stillcompute.hpp"
3635
#include "framework-frontend.hpp"
37-
#include "framework-stillcompute.hpp"
3836
#include "framework-utiles.hpp"
3937
#include "ThreadPool.h"
4038

0 commit comments

Comments
 (0)