00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00039
00040 #define SHOW_RECONSTRUCTION
00041
00042 #include <QVApplication>
00043 #include <QTime>
00044 #include <qvsfm.h>
00045 #include <sfmviewer.h>
00046
00047
00048 void printReconstructionStats( const QList<QVCameraPose> &cameraPoses,
00049 const QList<QV3DPointF> &points3D,
00050 const QList< QHash< int, QPointF> > &pointsTrackings)
00051 {
00052 const int numCameras = cameraPoses.count(), numPoints = points3D.count();
00053 int numProjections = 0;
00054 QHash< int, QPointF> temp;
00055 foreach(temp, pointsTrackings)
00056 numProjections += temp.count();
00057
00058 std::cout << "[main] Readed " << numPoints << " points, "
00059 << numCameras << " cameras, "
00060 << numProjections << " projections, "
00061 << double(numProjections)/double(numCameras) << " projections/camera, "
00062 << double(numProjections)/double(numPoints) << " projections/point."
00063 << std::endl;
00064 }
00065
00066 int main(int argc, char *argv[])
00067 {
00068 #ifdef SHOW_RECONSTRUCTION
00069 QVApplication app(argc, argv, "Example application for QVision.", true);
00070 #else
00071 QVApplication app(argc, argv, "Example application for QVision.", false);
00072 #endif
00073
00074
00075 if (app.getNumberOfArguments() < 2)
00076 {
00077 std::cout << "Usage: " << std::endl << "\t" << argv[0] << " <data_set_path> [iterations] [lambda_sba]"
00078 << std::endl << std::endl;
00079 exit(0);
00080 }
00081
00082 const QString path = app.getArgument(1);
00083
00084
00085 bool iters_OK = true, lambda_sba_OK = true;
00086
00087 const int iters = (app.getNumberOfArguments() < 3)? 1 : app.getArgument(2).toInt(&iters_OK);
00088 const double lambda_sba = (app.getNumberOfArguments() < 4)? 1.0 : app.getArgument(3).toDouble(&lambda_sba_OK);
00089
00090 if (not iters_OK)
00091 {
00092 std::cout << "[main] Error reading number of iterations." << std::endl;
00093 exit(0);
00094 }
00095 else
00096 std::cout << "[main] Number of iterations = " << iters << std::endl;
00097
00098 if (not lambda_sba_OK)
00099 {
00100 std::cout << "[main] Error reading lambda for SBA optimization" << std::endl;
00101 exit(0);
00102 }
00103 else
00104 std::cout << "[main] Lambda for SBA = " << lambda_sba << std::endl;
00105
00106
00107 QList<QV3DPointF> points3D;
00108 QList<QVCameraPose> cameraPoses;
00109 QList<QVMatrix> cameraCalibrations;
00110 QList< QHash< int, QPointF> > pointsTrackings;
00111
00112 if( not readSfMReconstruction(path, cameraCalibrations, cameraPoses, points3D, pointsTrackings) )
00113 {
00114 std::cout << "[main] Error: could not read SfM reconstruction from path '" << qPrintable(path) << "'." << std::endl;
00115 return 0;
00116 }
00117
00118
00119 const QList< QHash< int, QPointF> > calibratedPointsTrackings = correctIntrinsics(cameraCalibrations, pointsTrackings);
00120
00121
00122 if (testCheirality(cameraPoses, calibratedPointsTrackings))
00123 invertCheirality(cameraPoses, points3D);
00124
00125
00126 std::cout << "[main] Reconstruction loaded."<< std::endl;
00127 printReconstructionStats(cameraPoses, points3D, calibratedPointsTrackings);
00128
00129
00130 QList<QV3DPointF> points3D_SBA;
00131 QList<QVCameraPose> cameraPoses_SBA;
00132 laSBAOptimization(cameraPoses, points3D, calibratedPointsTrackings, cameraPoses_SBA, points3D_SBA, iters, 0, 0, lambda_sba);
00133
00134
00135 std::cout << "[main] Initial error\t" << 1000.0 * reconstructionError(cameraPoses, points3D, calibratedPointsTrackings) << std::endl;
00136 std::cout << "[main] SBA error/time\t" << 1000.0 * reconstructionError(cameraPoses_SBA, points3D_SBA, calibratedPointsTrackings) << std::endl;
00137 std::cout << "[main] SBA2 error/time\t" << 1000.0 * reconstructionError(cameraPoses_SBA, linear3DPointsTriangulation(cameraPoses_SBA, calibratedPointsTrackings), calibratedPointsTrackings) << std::endl;
00138
00139 #ifdef SHOW_RECONSTRUCTION
00140 SfMViewer originalMap(cameraPoses, points3D, "Original reconstruction");
00141 SfMViewer sbaOptimizedMap(cameraPoses_SBA, points3D_SBA, "Reconstruction optimized with SBA");
00142 SfMViewer sbaOptimizedMap2(cameraPoses_SBA, linear3DPointsTriangulation(cameraPoses_SBA, calibratedPointsTrackings), "Reconstruction optimized with SBA 2");
00143 return app.exec();
00144 #endif // SHOW_RECONSTRUCTION
00145
00146 exit(0);
00147 }
00148