app-ChipValidatorGui.C
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "QtUtil/Util.H"
00039 #include "NeovisionII/ChipValidator/ChipValidatorQt.qt.H"
00040 #include "Image/Image.H"
00041 #include "Image/PixelsTypes.H"
00042 #include "Raster/Raster.H"
00043 #include "Util/sformat.H"
00044
00045 #include <QtGui/QApplication>
00046
00047 #include <sys/types.h>
00048 #include <dirent.h>
00049 #include <sys/stat.h>
00050
00051 bool sortChips(const ChipData& d1, const ChipData& d2)
00052 {
00053 return d1.file < d2.file;
00054 }
00055
00056
00057 void loadChips(std::vector<ChipData>& vec, const std::string& path, const bool positive)
00058 {
00059 DIR *dir = opendir(path.c_str());
00060 if (dir == NULL) PLFATAL("Cannot opendir '%s'", path.c_str());
00061
00062 struct dirent *entry;
00063 while ( (entry = readdir(dir)) ) {
00064 if (entry->d_name[0] == '.') continue;
00065 ChipData cdata;
00066 std::string fullname = sformat("%s/%s", path.c_str(), entry->d_name);
00067 cdata.image = Raster::ReadRGB(fullname);
00068 cdata.file = entry->d_name;
00069 cdata.positive = positive;
00070
00071 vec.push_back(cdata);
00072 }
00073
00074 std::sort(vec.begin(),vec.end(),sortChips);
00075 if (closedir(dir)) PLFATAL("Error closing directory '%s'", path.c_str());
00076 }
00077
00078
00079
00080
00081
00082 int main(int argc, const char **argv)
00083 {
00084 LOG_FLAGS &= (~LFATAL_XTRA_NOISY); LOG_FLAGS &= (~LFATAL_PRINTS_ABORT);
00085
00086 if (argc != 3) LFATAL("USAGE: %s <indir> <outdir>", argv[0]);
00087
00088
00089 mode_t mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
00090 if (mkdir(argv[2], mode)) PLFATAL("Error creating output directory '%s'", argv[2]);
00091 if (mkdir(sformat("%s/tp", argv[2]).c_str(), mode)) PLFATAL("Error creating output directory '%s/tp/'", argv[2]);
00092 if (mkdir(sformat("%s/tn", argv[2]).c_str(), mode)) PLFATAL("Error creating output directory '%s/tn/'", argv[2]);
00093
00094
00095 std::vector<ChipData> chipvec;
00096 LINFO("Loading true positive chips from '%s/tp/' ...", argv[1]);
00097 loadChips(chipvec, sformat("%s/tp", argv[1]), true);
00098 LINFO("Loading true negative chips from '%s/tn/' ...", argv[1]);
00099 loadChips(chipvec, sformat("%s/tn", argv[1]), false);
00100 LINFO(" ... loaded %"ZU" chips in total", chipvec.size());
00101
00102
00103 LINFO("Starting GUI...");
00104 int qtargc = 1; const char* qtargv[1] = { "ChipValidatorGui" };
00105 QApplication a(qtargc, argv2qt(qtargc, qtargv));
00106
00107
00108 const Dims griddims(9, 5);
00109 ChipValidatorQt cqt(&a, chipvec, griddims);
00110 cqt.setWindowTitle("iLab USC -- Chip Validator GUI");
00111 cqt.show();
00112
00113
00114 const int ret = a.exec();
00115
00116
00117 LINFO("Saving %"ZU" validated chips to '%s'", chipvec.size(), argv[2]);
00118 for (size_t i = 0; i < chipvec.size(); ++i)
00119 Raster::WriteRGB(chipvec[i].image,
00120 sformat("%s/%s/%s", argv[2], chipvec[i].positive ? "tp" : "tn", chipvec[i].file.c_str()));
00121 LINFO("All Done.");
00122
00123
00124 return ret;
00125 }