app-sc-map.C
Go to the documentation of this file.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 APPNEURO_APP_SC_MAP_C_DEFINED
00039 #define APPNEURO_APP_SC_MAP_C_DEFINED
00040
00041 #include "Channels/InputFrame.H"
00042 #include "Component/ModelManager.H"
00043 #include "GUI/XWinManaged.H"
00044 #include "Image/DrawOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/LogPolarTransform.H"
00047 #include "Image/Normalize.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/ShapeOps.H"
00050 #include "Media/FrameSeries.H"
00051 #include "Channels/RawVisualCortex.H"
00052 #include "Neuro/VisualCortexConfigurator.H"
00053 #include "Raster/GenericFrame.H"
00054 #include "Raster/Raster.H"
00055 #include "Transport/FrameInfo.H"
00056 #include "Util/CpuTimer.H"
00057 #include "Util/Pause.H"
00058 #include "Util/csignals.H"
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 int submain(const int argc, const char **argv)
00123 {
00124 volatile int signum = 0;
00125 catchsignals(&signum);
00126
00127 ModelManager manager("Streamer");
00128
00129 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00130 manager.addSubComponent(ifs);
00131
00132 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00133 manager.addSubComponent(ofs);
00134
00135 nub::ref<RawVisualCortex> vcx(new RawVisualCortex(manager));
00136 manager.addSubComponent(vcx);
00137
00138 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false)
00139 return(1);
00140
00141 manager.start();
00142
00143 ifs->startStream();
00144
00145 const Dims indims = ifs->peekDims();
00146
00147 LogPolarTransform t(indims, Dims(375, 200), 0.3, 0.2);
00148
00149 int c = 0;
00150
00151 PauseWaiter p;
00152
00153 SimTime tm = SimTime::ZERO();
00154
00155 while (true)
00156 {
00157 if (signum != 0)
00158 {
00159 LINFO("quitting because %s was caught", signame(signum));
00160 return -1;
00161 }
00162
00163 if (ofs->becameVoid())
00164 {
00165 LINFO("quitting because output stream was closed or became void");
00166 return 0;
00167 }
00168
00169 if (p.checkPause())
00170 continue;
00171
00172 const FrameState is = ifs->updateNext();
00173 if (is == FRAME_COMPLETE)
00174 break;
00175
00176 GenericFrame input = ifs->readFrame();
00177 if (!input.initialized())
00178 break;
00179
00180 const Image<PixRGB<byte> > rgbin = input.asRgb();
00181
00182 vcx->input(InputFrame::fromRgb(&rgbin, tm));
00183
00184 const Image<float> vcxmap = rescaleBilinear(vcx->getOutput(), input.getDims());
00185
00186 const FrameState os = ofs->updateNext();
00187
00188 const Image<PixRGB<byte> > txf = logPolarTransform(t, input.asRgb(), PixRGB<byte>(255));
00189
00190 const Image<float> txfsalmap = logPolarTransform(t, vcxmap, float(0.0f));
00191
00192 ofs->writeFrame(input, "input",
00193 FrameInfo("input frame", SRC_POS));
00194
00195 ofs->writeRGB(txf, "logpolar",
00196 FrameInfo("log-polar transform of input frame", SRC_POS));
00197
00198 ofs->writeFloat(vcxmap, FLOAT_NORM_0_255, "vcxmap",
00199 FrameInfo("VisualCortex output", SRC_POS));
00200
00201 ofs->writeFloat(txfsalmap, FLOAT_NORM_0_255, "txfsalmap",
00202 FrameInfo("Log-Polar VisualCortex output", SRC_POS));
00203
00204 {
00205 Image<byte> vcxmapb = normalizeFloat(vcxmap, FLOAT_NORM_0_255);
00206 Image<byte> txfsalmapb = normalizeFloat(txfsalmap, FLOAT_NORM_0_255);
00207
00208 const Image<PixRGB<byte> > vcxmapn(vcxmapb);
00209 const Image<PixRGB<byte> > txfsalmapn(txfsalmapb);
00210
00211 ofs->writeRgbLayout(hcat(vcat(rescaleBilinear(rgbin, 372,279), txf),
00212 vcat(rescaleBilinear(vcxmapn, 372,279), txfsalmapn)),
00213 "grid");
00214 }
00215
00216 if (os == FRAME_FINAL)
00217 break;
00218
00219 LDEBUG("frame %d", c++);
00220
00221 if (ifs->shouldWait() || ofs->shouldWait())
00222 Raster::waitForKey();
00223
00224 tm += SimTime::HERTZ(30);
00225 }
00226
00227 return 0;
00228 }
00229
00230 int main(const int argc, const char **argv)
00231 {
00232 try
00233 {
00234 return submain(argc, argv);
00235 }
00236 catch (...)
00237 {
00238 REPORT_CURRENT_EXCEPTION;
00239 }
00240
00241 return 1;
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251 #endif // APPNEURO_APP_SC_MAP_C_DEFINED