00001 #include <iomanip>
00002
00003 #include "Basis/CmdOptions.h"
00004 #include "Util/Channel.h"
00005 #include "Util/ChannelPool.h"
00006 #include "Basis/Timer.h"
00007 #include "Core/Geometry/PointZList.h"
00008 #include "Core/Array/Arrays.h"
00009 #include "Core/Array/RGB2Intensity.h"
00010 #include "Core/Array/GetRgbPixels.h"
00011 #include "Core/Array/GaussDerivative.h"
00012 #include "Core/Array/WriteRaw.h"
00013 #include "Core/Array/ProjectRange.h"
00014 #include "Core/Array/GaussDerivative.h"
00015 #include "Core/Array/Trait/BpoEqual.h"
00016 #include "Core/Array/Harris.h"
00017 #include "Core/Array/InvCompDer.h"
00018 #include "Core/Array/Dilation.h"
00019 #include "Core/Array/Set.h"
00020 #include "Core/Matrix/MatSet.h"
00021 #include "Core/Stream/RgbDataSrcFactory.h"
00022
00023
00024 #include "Link/ImpalaLib.cpp"
00025
00026 namespace Impala
00027 {
00028 namespace Application
00029 {
00030 namespace Client
00031 {
00032
00033
00034 using namespace Impala::Core::Array;
00035 using namespace Impala::Core::Stream;
00036
00037 int gNrIter;
00038
00039 void
00040 ExampleReadRaw(Util::Channel* chanP)
00041 {
00042 ILOG_VAR(Impala.Application.Client.ExampleReadRaw);
00043 CmdOptions& options = CmdOptions::GetInstance();
00044
00045 Util::Channel& chan = *chanP;
00046 char* buf = chan.Buffer();
00047 int len;
00048
00049
00050 ILOG_DEBUG("requesting readraw");
00051 String fileName = "trui.raw";
00052 if (options.GetNrArg() > 2)
00053 fileName = options.GetArg(2);
00054 Array2dVec3UInt8* src = 0;
00055 Util::IOBuffer* ioBuf = ReadIOBufferFromChannel(chanP, fileName, "");
00056 ReadRaw(src, ioBuf);
00057 delete ioBuf;
00058 Array2dVec3Real64* srcV3R64 = 0;
00059 Set(srcV3R64, src);
00060
00061
00062 Array2dScalarReal64* srcSR64 = 0;
00063 RGB2Intensity(srcSR64, srcV3R64);
00064
00065
00066 ILOG_DEBUG("requesting opendst");
00067 int width = src->CW();
00068 int height = src->CH();
00069 sprintf(buf, "opendst %d %d\0", width, height);
00070 len = chan.SendRequest(strlen(buf)+1);
00071
00072
00073 ILOG_DEBUG("requesting show");
00074 sprintf(buf, "show\0");
00075 GetRgbPixels(srcSR64, (UInt8*)(buf + 5), "Stretch");
00076 len = chan.SendRequest(width*height*3 + 5);
00077
00078
00079 for (int j=1 ; j<gNrIter ; j++)
00080 {
00081 for (int i=1 ; i<10 ; i++)
00082 {
00083 double sigma = 0.5 * i;
00084 Array2dScalarReal64* res = 0;
00085 GaussDerivative(res, srcSR64, sigma, 0, 0, 3.0);
00086 ILOG_DEBUG("requesting show " << i);
00087 sprintf(buf, "show\0");
00088 GetRgbPixels(res, (UInt8*)(buf + 5), "Stretch");
00089 len = chan.SendRequest(width*height*3 + 5);
00090 }
00091 }
00092 }
00093
00094 void
00095 ExampleRgbDataSrc(Util::Channel* chanP)
00096 {
00097 ILOG_VAR(Impala.Application.Client.ExampleRgbDataSrc);
00098 CmdOptions& options = CmdOptions::GetInstance();
00099
00100 Util::Channel& chan = *chanP;
00101 chan.MaximizeSendRecvBuffer();
00102 char* buf = chan.Buffer();
00103 int len;
00104
00105
00106 String fileName = "bike.mpg";
00107 if (options.GetNrArg() > 2)
00108 fileName = options.GetArg(2);
00109 sprintf(buf, "opensrc \"%s\"\0", fileName.c_str());
00110 len = chan.SendRequest(strlen(buf)+1);
00111 buf[len] = 0;
00112 ILOG_INFO("answer : (" << len << " bytes) = [" << buf << "]");
00113 int width;
00114 int height;
00115 sscanf(buf, "%d %d", &width, &height);
00116 ILOG_INFO("sizes : " << width << " x " << height);
00117
00118
00119 sprintf(buf, "opendst %d %d\0", width, height);
00120 len = chan.SendRequest(strlen(buf)+1);
00121
00122 Timer theTimer(1);
00123 for (int i=1 ; i<gNrIter ; i++)
00124 {
00125
00126 sprintf(buf, "nextframe\0");
00127 len = chan.SendRequest(strlen(buf)+1);
00128
00129
00130 Array2dVec3UInt8* srcWrap =
00131 ArrayCreate<Array2dVec3UInt8>(width, height, 0, 0, (UInt8*) buf,
00132 true);
00133 Array2dVec3Real64* srcV3R64 = 0;
00134 Set(srcV3R64, srcWrap);
00135
00136
00137 Array2dScalarReal64* srcSR64 = 0;
00138 RGB2Intensity(srcSR64, srcV3R64);
00139
00140
00141
00142 sprintf(buf, "show\0");
00143 GetRgbPixels(srcSR64, (UInt8*)(buf + 5), "Stretch");
00144 len = chan.SendRequest(width*height*3 + 5);
00145
00146 double timeVal = theTimer.SplitTime();
00147 double fps = (double) i / timeVal;
00148 double bps = (2.0*i * width*height*3) / (1024.0*1024 * timeVal);
00149 std::cout << "Did " << i << " frames in " << std::setw(8) << std::left
00150 << timeVal << " sec = " << std::setw(8) << fps << " fps and "
00151 << std::setw(8) << bps << " Mb/sec" << std::endl;
00152
00153 delete srcWrap;
00154 delete srcV3R64;
00155 delete srcSR64;
00156 }
00157 }
00158
00159 void
00160 TestBandwidth(Util::Channel* chanP)
00161 {
00162 ILOG_VAR(Impala.Application.Client.TestBandwidth);
00163 CmdOptions& options = CmdOptions::GetInstance();
00164
00165 Util::Channel& chan = *chanP;
00166 char* buf = chan.Buffer();
00167
00168 int width = 352;
00169 if (options.GetNrArg() > 2)
00170 width = atol(options.GetArg(2));
00171 int height = 288;
00172 if (options.GetNrArg() > 3)
00173 height = atol(options.GetArg(3));
00174 ILOG_INFO("sizes : " << width << " x " << height);
00175
00176 bool doWrite = false;
00177 Timer theTimer(1);
00178 for (int i=1 ; i<gNrIter ; i++)
00179 {
00180
00181 ILOG_DEBUG("requesting testdata");
00182 int nrBytes = width * height * 3;
00183 sprintf(buf, "testdata %d\0", nrBytes);
00184 int len = chan.SendRequest(strlen(buf)+1);
00185
00186 if (doWrite)
00187 {
00188
00189 Array2dVec3UInt8* srcWrap =
00190 ArrayCreate<Array2dVec3UInt8>(width, height, 0, 0, (UInt8*) buf,
00191 true);
00192 Array2dVec3Real64* srcV3R64 = 0;
00193 Set(srcV3R64, srcWrap);
00194
00195
00196 Array2dScalarReal64* srcSR64 = 0;
00197 RGB2Intensity(srcSR64, srcV3R64);
00198
00199
00200 if (i < 5)
00201 WriteRaw(srcSR64, "res.raw" + MakeString(i),
00202 &Util::Database::GetInstance(), false);
00203
00204 delete srcWrap;
00205 delete srcV3R64;
00206 delete srcSR64;
00207 }
00208 double timeVal = theTimer.SplitTime();
00209 double fps = (double) i / timeVal;
00210 double bps = (1.0*i * width*height*3) / (1024.0*1024 * timeVal);
00211 std::cout << "Did " << i << " frames in " << std::setw(8) << std::left
00212 << timeVal << " sec = " << std::setw(8) << fps << " fps and "
00213 << std::setw(8) << bps << " Mb/sec" << std::endl;
00214 }
00215 }
00216
00217 void
00218 TestMpg(Util::Channel* chanP)
00219 {
00220 ILOG_VAR(Impala.Application.Client.TestMpg);
00221 CmdOptions& options = CmdOptions::GetInstance();
00222
00223 Util::Channel& chan = *chanP;
00224 char* buf = chan.Buffer();
00225 int len;
00226
00227
00228 String fileName = "ANNA4.MPEG";
00229 if (options.GetNrArg() > 2)
00230 fileName = options.GetArg(2);
00231 ILOG_DEBUG("opening src " << fileName);
00232 RgbDataSrcFactory& factory = RgbDataSrcFactory::Instance();
00233 RgbDataSrc* theSrc = factory.Construct(fileName, options.GetString("src"));
00234 int width = theSrc->FrameWidth();
00235 int height = theSrc->FrameHeight();
00236 ILOG_INFO("sizes : " << width << " x " << height);
00237
00238
00239 ILOG_DEBUG("requesting opendst");
00240 sprintf(buf, "opendst %d %d\0", width, height);
00241 len = chan.SendRequest(strlen(buf)+1);
00242
00243 Timer theTimer(1);
00244 for (int i=1 ; i<gNrIter ; i++)
00245 {
00246
00247 ILOG_DEBUG("doing nextframe");
00248 theSrc->NextFrame(1);
00249
00250
00251 Array2dVec3UInt8* srcWrap =
00252 ArrayCreate<Array2dVec3UInt8>(width, height, 0, 0,
00253 theSrc->DataPtr(), true);
00254
00255
00256 sprintf(buf, "show\0");
00257 GetRgbPixels(srcWrap, (UInt8*)(buf + 5), "Direct");
00258 len = chan.SendRequest(width*height*3 + 5);
00259
00260 double timeVal = theTimer.SplitTime();
00261 double fps = (double) i / timeVal;
00262 double bps = (1.0*i * width*height*3) / (1024.0*1024 * timeVal);
00263 std::cout << "Did " << i << " frames in " << std::setw(8) << std::left
00264 << timeVal << " sec = " << std::setw(8) << fps << " fps and "
00265 << std::setw(8) << bps << " Mb/sec" << std::endl;
00266
00267 delete srcWrap;
00268 }
00269 }
00270
00271 int
00272 mainClient(int argc, char* argv[])
00273 {
00274 CmdOptions& options = CmdOptions::GetInstance();
00275 options.Initialise(true, false, true);
00276 options.AddOption(0, "file", "name", "");
00277 options.AddOption(0, "iter", "number", "1000");
00278 options.AddOption(0, "skip", "nrFrames", "0");
00279 String usageStr = "machine:port cmd = \n\n";
00280 usageStr += " raw [trui.raw]\n";
00281 usageStr += " src [bike.mpg]\n";
00282 usageStr += " test [352] [288]\n";
00283 usageStr += " mpg [ANNA4.MPEG]\n";
00284 if (! options.ParseArgs(argc, argv, usageStr, 2))
00285 return 1;
00286
00287 ILOG_VAR(Impala.Application.Client.mainClient);
00288
00289 String server = options.GetArg(0);
00290 if (server.empty())
00291 {
00292 ILOG_ERROR("need dataServer");
00293 return 1;
00294 }
00295 String passwordFile = options.GetString("passwordFile");
00296 Util::Channel* chanP = Util::ChannelPool::Instance().Get(server,
00297 passwordFile);
00298 if (!chanP || !chanP->Valid())
00299 {
00300 ILOG_ERROR("No Channel");
00301 return 1;
00302 }
00303
00304 gNrIter = options.GetInt("iter");
00305
00306 String cmd = options.GetArg(1);
00307
00308 if (cmd == "raw")
00309 ExampleReadRaw(chanP);
00310 else if (cmd == "src")
00311 ExampleRgbDataSrc(chanP);
00312 else if (cmd == "test")
00313 TestBandwidth(chanP);
00314 else if (cmd == "mpg")
00315 TestMpg(chanP);
00316
00317 return 0;
00318 }
00319
00320 }
00321 }
00322 }
00323
00324 int
00325 main(int argc, char* argv[])
00326 {
00327 return Impala::Application::Client::mainClient(argc, argv);
00328 }