app-train-need-for-speed.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 #ifndef APPMEDIA_APP_TRAIN_NEED_FOR_SPEED_C_DEFINED
00039 #define APPMEDIA_APP_TRAIN_NEED_FOR_SPEED_C_DEFINED
00040
00041 #include "GUI/XWinManaged.H"
00042 #include "Image/ColorOps.H"
00043 #include "Image/CutPaste.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "Image/Point2D.H"
00047 #include "Image/ShapeOps.H"
00048 #include "Raster/Raster.H"
00049 #include "Util/log.H"
00050 #include "Util/sformat.H"
00051 #include "Video/VideoFrame.H"
00052 #include "rutz/rand.h"
00053
00054 #include <fstream>
00055 #include <iostream>
00056 #include <limits>
00057 #include <sstream>
00058 #include <sys/types.h>
00059 #include <unistd.h>
00060 #include <vector>
00061
00062 int main(const int argc, const char** argv)
00063 {
00064 if (argc != 3)
00065 {
00066 LFATAL("usage: %s <imagelist> <dataout>", argv[0]);
00067 }
00068
00069 std::vector<std::string> fnames;
00070 std::vector<unsigned char> done;
00071
00072 {
00073 std::ifstream ifs(argv[1]);
00074
00075 std::string fname;
00076 while (ifs >> fname)
00077 fnames.push_back(fname);
00078
00079 ifs.close();
00080 }
00081
00082 done.resize(fnames.size(), (unsigned char)0);
00083
00084 rutz::urand_irange rnd(0, int(fnames.size()), int(getpid()));
00085
00086 const Dims zoomdims(121,69);
00087
00088 XWinManaged fullwin(Dims(640,480), -1, -1, "full");
00089 XWinManaged zoomwin(zoomdims * 2, -1, -1, "zoom");
00090
00091 std::ofstream ofs(argv[2], std::ios::app);
00092
00093 while (1)
00094 {
00095 int p = 0;
00096 do {
00097 p = rnd.draw();
00098 } while (done[p]);
00099
00100 const char* imname = fnames[p].c_str();
00101 done[p] = 1;
00102
00103 const VideoFrame vf = VideoFrame::fromFile(imname, Dims(640,480),
00104 VIDFMT_UYVY, false);
00105
00106 const int bottom = rnd.draw() % 2;
00107
00108 const VideoFrame vf2 = vf.makeBobDeinterlaced(bottom);
00109
00110 const Image<PixRGB<byte> > rgb = vf2.toRgb();
00111
00112 const std::string rgbname = sformat("%s-%d.png", imname, bottom);
00113
00114 if (Raster::fileExists(rgbname))
00115 {
00116 std::cout << "already exists: " << rgbname << std::endl;
00117 continue;
00118 }
00119
00120 const Image<PixRGB<byte> > im2 = crop(rgb, Point2D<int>(453, 86), zoomdims);
00121
00122 fullwin.drawImage(rgb, 0, 0);
00123 zoomwin.drawImage(intXY(im2, true), 0, 0);
00124
00125 std::cout << imname << "? " << std::flush;
00126
00127 std::string line;
00128 std::getline(std::cin, line);
00129
00130 if (line == "end")
00131 break;
00132
00133 if (line.size() > 0)
00134 {
00135 std::istringstream iss(line);
00136
00137 std::string s[4];
00138
00139 iss >> s[0] >> s[1] >> s[2] >> s[3];
00140
00141 bool ok = true;
00142 bool gotilab = false;
00143
00144 for (size_t i = 0; i < 4; ++i)
00145 {
00146 if (s[i].length() == 0) ok = false;
00147 else if (s[i] == "ilab") gotilab = true;
00148 }
00149
00150 if (ok && gotilab)
00151 {
00152 for (size_t i = 0; i < 4; ++i)
00153 std::cout << s[i] << std::endl;
00154
00155 ofs << sformat("%-50s\t%8s\t%8s\t%8s\t%8s",
00156 rgbname.c_str(),
00157 s[0].c_str(), s[1].c_str(),
00158 s[2].c_str(), s[3].c_str())
00159 << std::endl;
00160
00161 Raster::WriteRGB(rgb, rgbname);
00162 }
00163 else
00164 {
00165 std::cout << "skipped" << std::endl;
00166 }
00167 }
00168 }
00169
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179 #endif // APPMEDIA_APP_TRAIN_NEED_FOR_SPEED_C_DEFINED