Go to the documentation of this file.00001
00034 #include <iostream>
00035 #include <fstream>
00036 #include <opencv/cv.h>
00037 #include <opencv/highgui.h>
00038 #include <string>
00039 #include <vector>
00040
00041 #include "Mask.h"
00042
00043 #include "DUtils.h"
00044 #include "DUtilsCV.h"
00045 #include "DVision.h"
00046
00047 typedef DVision::PixelPointFile PixelPointFile;
00048 typedef DVision::PixelPointFile::PixelPoint PixelPoint;
00049 typedef DVision::SurfSet SurfSet;
00050 typedef DVision::PMVS::PLYFile PLYFile;
00051 typedef DVision::PMVS::PLYFile::PLYPoint PLYPoint;
00052
00053 using namespace std;
00054
00055 void treatDirectory(const std::string &img_dir);
00056
00057 void readPLYindices(const std::string &indice_file,
00058 vector<int> &ply_indices);
00059
00060 void getPoints(const vector<PLYPoint> &all_plypoints,
00061 const vector<int> &ply_indices, vector<PLYPoint> &plypoints);
00062
00063
00064
00065 int main(int argc, char *argv[])
00066 {
00067 if(argc < 2)
00068 {
00069 cout << "Usage: " << argv[0] << " <img dir>"
00070 << endl;
00071 return 1;
00072 }
00073
00074 string img_dir = argv[1];
00075
00076 try
00077 {
00078 treatDirectory(img_dir);
00079 }
00080 catch(std::string ex)
00081 {
00082 cout << ex << endl;
00083 }
00084
00085 return 0;
00086
00087 }
00088
00089
00090
00091 void treatDirectory(const std::string &img_dir)
00092 {
00093 vector<string> img_files =
00094 DUtils::FileFunctions::Dir(img_dir.c_str(), ".jpg", true);
00095
00096 cout << "-- " << img_files.size() << " images read" << endl;
00097
00098 for(unsigned int i = 0; i < img_files.size(); ++i)
00099 {
00100 const string& img_file = img_files[i];
00101
00102 cout << img_file << "..." << endl;
00103
00104 string path, name, ext;
00105 DUtils::FileFunctions::FileParts(img_file, path, name, ext);
00106
00107 const string indice_file = path + "/" + name + "_2d3d.txt";
00108 const string all_ply_file = path + "/" + "dense_model" + ".ply";
00109
00110 vector<PLYPoint> all_plypoints;
00111 PLYFile::readFile(all_ply_file, all_plypoints);
00112
00113 cout << "-- " << all_plypoints.size() << " PLY points read from "
00114 << all_ply_file << endl;
00115
00116 vector<int> ply_indices;
00117 readPLYindices(indice_file, ply_indices);
00118
00119 vector<PLYPoint> plypoints;
00120 getPoints(all_plypoints, ply_indices, plypoints);
00121
00122
00123 const string ply_file = path + "/" + name + ".ply";
00124 PLYFile::saveFile(ply_file, plypoints);
00125 }
00126
00127 }
00128
00129
00130
00131 void readPLYindices(const std::string &indice_file,
00132 vector<int> &ply_indices)
00133 {
00134 ply_indices.clear();
00135
00136 fstream f(indice_file.c_str(), ios::in);
00137
00138 if(!f.is_open())
00139 {
00140 throw string("Could not open file ") + indice_file;
00141 }
00142
00143 int N;
00144 f >> N;
00145
00146 for(int i = 0; i < N; ++i)
00147 {
00148 int key_idx, ply_idx;
00149 f >> key_idx >> ply_idx;
00150
00151 ply_indices.push_back(ply_idx);
00152 }
00153
00154 f.close();
00155 }
00156
00157
00158
00159 void getPoints(const vector<PLYPoint> &all_plypoints,
00160 const vector<int> &ply_indices, vector<PLYPoint> &plypoints)
00161 {
00162 plypoints.clear();
00163 plypoints.reserve(ply_indices.size());
00164
00165 vector<int>::const_iterator it;
00166 for(it = ply_indices.begin(); it != ply_indices.end(); ++it)
00167 {
00168 int idx = *it;
00169 plypoints.push_back(all_plypoints[idx]);
00170 }
00171 }
00172
00173
00174