Fix in running incremental optimization on Kitti
parent
3c68d20ff2
commit
4996db5023
|
|
@ -68,9 +68,6 @@ typedef FastMap<Key, std::vector<boost::shared_ptr<ProjectionFactor> > > Project
|
||||||
|
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
|
|
||||||
static double KittiLinThreshold = -1; // 1e-7; // 0.01
|
|
||||||
static double KittiRankTolerance = 1; //1;
|
|
||||||
|
|
||||||
//// Helper functions taken from VO code
|
//// Helper functions taken from VO code
|
||||||
// Loaded all pose values into list
|
// Loaded all pose values into list
|
||||||
Values::shared_ptr loadPoseValues(const string& filename) {
|
Values::shared_ptr loadPoseValues(const string& filename) {
|
||||||
|
|
@ -338,10 +335,16 @@ int main(int argc, char** argv) {
|
||||||
unsigned int maxNumPoses = 45400; //3541
|
unsigned int maxNumPoses = 45400; //3541
|
||||||
|
|
||||||
// Set to true to use SmartProjectionFactor. Otherwise GenericProjectionFactor will be used
|
// Set to true to use SmartProjectionFactor. Otherwise GenericProjectionFactor will be used
|
||||||
bool useSmartProjectionFactor = false;
|
bool useSmartProjectionFactor = true;
|
||||||
bool useTriangulation = true;
|
bool useTriangulation = true;
|
||||||
bool useLM = true;
|
bool useLM = true;
|
||||||
|
|
||||||
|
double KittiLinThreshold = -1; // 1e-7; // 0.01
|
||||||
|
double KittiRankTolerance = 1;
|
||||||
|
|
||||||
|
bool incrementalFlag = true;
|
||||||
|
int optSkip = 200; // we optimize the graph every optSkip poses
|
||||||
|
|
||||||
std::cout << "PARAM SmartFactor: " << useSmartProjectionFactor << std::endl;
|
std::cout << "PARAM SmartFactor: " << useSmartProjectionFactor << std::endl;
|
||||||
std::cout << "PARAM Triangulation: " << useTriangulation << std::endl;
|
std::cout << "PARAM Triangulation: " << useTriangulation << std::endl;
|
||||||
std::cout << "PARAM LM: " << useLM << std::endl;
|
std::cout << "PARAM LM: " << useLM << std::endl;
|
||||||
|
|
@ -393,26 +396,33 @@ int main(int argc, char** argv) {
|
||||||
Values result;
|
Values result;
|
||||||
int totalNumMeasurements = 0;
|
int totalNumMeasurements = 0;
|
||||||
bool optimized = false;
|
bool optimized = false;
|
||||||
|
|
||||||
|
// main loop: reads measurements and adds factors (also performs optimization if desired)
|
||||||
while (fin >> r >> l >> uL >> uR >> v >> x >> y >> z) {
|
while (fin >> r >> l >> uL >> uR >> v >> x >> y >> z) {
|
||||||
if (debug) fprintf(stderr,"Landmark %ld\n", l);
|
if (debug) fprintf(stderr,"Landmark %ld\n", l);
|
||||||
if (debug) fprintf(stderr,"Line %d: %d landmarks, (max landmarks %d), %d poses, max poses %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
if (debug) fprintf(stderr,"Line %d: %d landmarks, (max landmarks %d), %d poses, max poses %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
||||||
|
|
||||||
// Optimize if have a certain number of poses/landmarks
|
// Optimize if have a certain number of poses/landmarks, or we want to do incremental inference
|
||||||
if (currentLandmark != l && (numPoses > maxNumPoses || numLandmarks > maxNumLandmarks) ) {
|
if (currentLandmark != l && (numPoses > maxNumPoses || numLandmarks > maxNumLandmarks || (incrementalFlag && !optimized && ((numPoses+1) % optSkip)==0 )) ) {
|
||||||
|
|
||||||
if (debug) fprintf(stderr,"%d: %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
if (debug) fprintf(stderr,"%d: %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
||||||
|
|
||||||
if (debug) cout << "Adding triangulated landmarks, graph size: " << graph.size() << endl;
|
if (debug) cout << "Adding triangulated landmarks, graph size: " << graph.size() << endl;
|
||||||
|
|
||||||
if (useSmartProjectionFactor == false && useTriangulation) {
|
if (useSmartProjectionFactor == false && useTriangulation) {
|
||||||
addTriangulatedLandmarks(graph, loadedValues, graphValues, K, projectionFactors);
|
addTriangulatedLandmarks(graph, loadedValues, graphValues, K, projectionFactors);
|
||||||
}
|
}
|
||||||
if (debug) cout << "Adding triangulated landmarks, graph size after: " << graph.size() << endl;
|
|
||||||
|
|
||||||
|
if (debug) cout << "Adding triangulated landmarks, graph size after: " << graph.size() << endl;
|
||||||
if (1||debug) fprintf(stderr,"%d: %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
if (1||debug) fprintf(stderr,"%d: %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
||||||
|
|
||||||
|
// optimize
|
||||||
if (useLM)
|
if (useLM)
|
||||||
optimizeGraphLM(graph, graphValues, result);
|
optimizeGraphLM(graph, graphValues, result);
|
||||||
else
|
else
|
||||||
optimizeGraphISAM2(graph, graphValues, result);
|
optimizeGraphISAM2(graph, graphValues, result);
|
||||||
|
|
||||||
|
if(incrementalFlag) *graphValues = result; // we use optimized solution as initial guess for the next one
|
||||||
|
|
||||||
optimized = true;
|
optimized = true;
|
||||||
|
|
||||||
// Only process first N measurements (for development/debugging)
|
// Only process first N measurements (for development/debugging)
|
||||||
|
|
@ -420,12 +430,12 @@ int main(int argc, char** argv) {
|
||||||
if (debug) fprintf(stderr,"%d: BREAKING %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
if (debug) fprintf(stderr,"%d: BREAKING %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
if(!incrementalFlag) break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add factors
|
||||||
|
// SMART FACTORS ..
|
||||||
if (useSmartProjectionFactor) {
|
if (useSmartProjectionFactor) {
|
||||||
|
|
||||||
// Check if landmark exists in mapping
|
// Check if landmark exists in mapping
|
||||||
SmartFactorToStateMap::iterator fsit = smartFactorStates.find(L(l));
|
SmartFactorToStateMap::iterator fsit = smartFactorStates.find(L(l));
|
||||||
SmartFactorMap::iterator fit = smartFactors.find(L(l));
|
SmartFactorMap::iterator fit = smartFactors.find(L(l));
|
||||||
|
|
@ -435,9 +445,10 @@ int main(int argc, char** argv) {
|
||||||
// Add measurement to smart factor
|
// Add measurement to smart factor
|
||||||
(*fit).second->add(Point2(uL,v), X(r));
|
(*fit).second->add(Point2(uL,v), X(r));
|
||||||
totalNumMeasurements++;
|
totalNumMeasurements++;
|
||||||
|
|
||||||
if (debug) (*fit).second->print();
|
if (debug) (*fit).second->print();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (debug) fprintf(stderr,"New landmark (%d,%d)\n", fsit != smartFactorStates.end(), fit != smartFactors.end());
|
if (debug) fprintf(stderr,"New landmark (%d,%d)\n", fsit != smartFactorStates.end(), fit != smartFactors.end());
|
||||||
|
|
||||||
views += X(r);
|
views += X(r);
|
||||||
|
|
@ -454,17 +465,17 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
views.clear();
|
views.clear();
|
||||||
measurements.clear();
|
measurements.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add initial pose value if pose does not exist
|
// Add initial pose value if pose does not exist
|
||||||
if (!graphValues->exists<Pose3>(X(r)) && loadedValues->exists<Pose3>(X(r))) {
|
if (!graphValues->exists<Pose3>(X(r)) && loadedValues->exists<Pose3>(X(r))) {
|
||||||
graphValues->insert(X(r), loadedValues->at<Pose3>(X(r)));
|
graphValues->insert(X(r), loadedValues->at<Pose3>(X(r)));
|
||||||
numPoses++;
|
numPoses++;
|
||||||
|
optimized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// or STANDARD PROJECTION FACTORS
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Create projection factor
|
// Create projection factor
|
||||||
ProjectionFactor::shared_ptr projectionFactor(new ProjectionFactor(Point2(uL,v), pixel_sigma, X(r), L(l), K));
|
ProjectionFactor::shared_ptr projectionFactor(new ProjectionFactor(Point2(uL,v), pixel_sigma, X(r), L(l), K));
|
||||||
|
|
||||||
|
|
@ -513,14 +524,11 @@ int main(int argc, char** argv) {
|
||||||
// Add projection factor to graph
|
// Add projection factor to graph
|
||||||
graph.push_back(projectionFactor);
|
graph.push_back(projectionFactor);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Alternatively: Triangulate similar to how SmartProjectionFactor does it
|
// Alternatively: Triangulate similar to how SmartProjectionFactor does it
|
||||||
// We only do this at the end, when all of the camera poses are available
|
// We only do this at the end, when all of the camera poses are available
|
||||||
// Note we do not add anything to the graph until then, since in some cases
|
// Note we do not add anything to the graph until then, since in some cases
|
||||||
// of triangulation failure we cannot add the landmark to the graph
|
// of triangulation failure we cannot add the landmark to the graph
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -537,6 +545,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
if (1||debug) fprintf(stderr,"%d: %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
if (1||debug) fprintf(stderr,"%d: %d > %d, %d > %d\n", count, numLandmarks, maxNumLandmarks, numPoses, maxNumPoses);
|
||||||
|
|
||||||
|
// if we haven't optimized yet
|
||||||
if (!optimized) {
|
if (!optimized) {
|
||||||
if (useSmartProjectionFactor == false && useTriangulation) {
|
if (useSmartProjectionFactor == false && useTriangulation) {
|
||||||
addTriangulatedLandmarks(graph, loadedValues, graphValues, K, projectionFactors);
|
addTriangulatedLandmarks(graph, loadedValues, graphValues, K, projectionFactors);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue