saveimage-server.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 "Component/ModelManager.H"
00039 #include "Learn/Bayes.H"
00040 #include "GUI/DebugWin.H"
00041 #include "NeovisionII/nv2_common.h"
00042 #include "NeovisionII/nv2_label_server.h"
00043
00044 #include "GUI/XWindow.H"
00045 #include "CUDA/CudaHmaxFL.H"
00046 #include "CUDA/CudaHmax.H"
00047 #include "CUDA/CudaImage.H"
00048 #include "Image/Image.H"
00049 #include "Image/ImageSet.H"
00050 #include "Image/ColorOps.H"
00051 #include "Image/ShapeOps.H"
00052 #include "Image/CutPaste.H"
00053 #include "Image/FilterOps.H"
00054 #include "Image/Rectangle.H"
00055 #include "Image/MathOps.H"
00056 #include "Image/DrawOps.H"
00057 #include "Image/MatrixOps.H"
00058 #include "Image/Transforms.H"
00059 #include "Image/Convolutions.H"
00060 #include "Learn/SVMClassifier.H"
00061 #include "Media/FrameSeries.H"
00062 #include "nub/ref.h"
00063 #include "Raster/GenericFrame.H"
00064 #include "Raster/Raster.H"
00065 #include "Util/Types.H"
00066 #include "Util/log.H"
00067
00068 #include <signal.h>
00069
00070 #include "rutz/fstring.h"
00071 #include "rutz/time.h"
00072 #include "rutz/timeformat.h"
00073
00074
00075 #include <fstream>
00076 #include <map>
00077 #include <vector>
00078 #include <utility>
00079 #include <iostream>
00080 #include <iomanip>
00081 #include <string>
00082 #include <unistd.h>
00083 #include <cstdlib>
00084
00085
00086
00087 #define NORI 4
00088 #define NUM_PATCHES_PER_SIZE 250
00089
00090
00091 const bool USECOLOR = false;
00092
00093 bool terminate = false;
00094
00095 void terminateProc(int s)
00096 {
00097 terminate = true;
00098 }
00099
00100
00101 int main(const int argc, const char **argv)
00102 {
00103
00104 MYLOGVERB = LOG_INFO;
00105
00106 ModelManager *mgr = new ModelManager("Hmax with Feature Learning Server");
00107
00108
00109 mgr->exportOptions(MC_RECURSE);
00110
00111
00112 if (mgr->parseCommandLine(
00113 (const int)argc, (const char**)argv, "<sampleimagesdir> <localport> <server_ip> <serverport> <prefix>", 4, 5) == false)
00114 return 1;
00115
00116 std::string serverIP,serverPortStr,localPortStr;
00117 std::string sampleImagesDir,prefixStr;
00118
00119
00120 mgr->start();
00121
00122
00123 signal(SIGHUP, terminateProc); signal(SIGINT, terminateProc);
00124 signal(SIGQUIT, terminateProc); signal(SIGTERM, terminateProc);
00125 signal(SIGALRM, terminateProc);
00126
00127
00128 sampleImagesDir = mgr->getExtraArg(0);
00129 localPortStr = mgr->getExtraArg(1);
00130 serverIP = mgr->getExtraArg(2);
00131 serverPortStr = mgr->getExtraArg(3);
00132 prefixStr = std::string("Sample");
00133 if(mgr->numExtraArgs() == 5)
00134 prefixStr = mgr->getExtraArg(4);
00135
00136 XWinManaged xwin(Dims(256,256),
00137 -1, -1, "ILab Robot Head Demo");
00138
00139 int serverPort = strtol(serverPortStr.c_str(),NULL,0);
00140 int localPort = strtol(localPortStr.c_str(),NULL,0);
00141 struct nv2_label_server* labelServer =
00142 nv2_label_server_create(localPort,
00143 serverIP.c_str(),
00144 serverPort);
00145
00146 nv2_label_server_set_verbosity(labelServer,1);
00147 int curPatch = 0;
00148
00149
00150
00151
00152
00153
00154
00155 while(!terminate)
00156 {
00157
00158
00159 struct nv2_image_patch p;
00160 const enum nv2_image_patch_result res =
00161 nv2_label_server_get_current_patch(labelServer, &p);
00162
00163 std::string objName;
00164 if (res == NV2_IMAGE_PATCH_END)
00165 {
00166 LINFO("ok, quitting");
00167 break;
00168 }
00169 else if (res == NV2_IMAGE_PATCH_NONE)
00170 {
00171 usleep(10000);
00172 continue;
00173 }
00174 else if (res == NV2_IMAGE_PATCH_VALID)
00175 {
00176 if (p.type != NV2_PIXEL_TYPE_RGB24)
00177 {
00178 LINFO("got a non-rgb24 patch; ignoring %i", p.type);
00179 continue;
00180 }
00181
00182 if (p.width * p.height == 1)
00183 {
00184
00185 continue;
00186 }
00187
00188 Image<PixRGB<byte> > img(p.width, p.height, NO_INIT);
00189
00190 memcpy(img.getArrayPtr(), p.data, p.width*p.height*3);
00191
00192 Image<PixRGB<byte> > inputImg = rescale(img, 256, 256);
00193
00194
00195
00196
00197 char fname[200];
00198 sprintf(fname,"%s/%s-%d.png",sampleImagesDir.c_str(),prefixStr.c_str(),curPatch);
00199 Raster::WriteRGB(inputImg,fname);
00200 curPatch++;
00201 }
00202 }
00203 if (terminate)
00204 LINFO("Ending application because a signal was caught");
00205
00206
00207 LINFO("Got Here");
00208
00209 return 0;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219