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
00039
00040
00041 #include "Beowulf/Beowulf.H"
00042 #include "Component/ModelManager.H"
00043 #include "Image/ColorOps.H"
00044 #include "Image/Image.H"
00045 #include "Image/ImageSet.H"
00046 #include "Image/Pixels.H"
00047 #include "Image/PyramidOps.H"
00048 #include "Image/ShapeOps.H"
00049 #include "Image/Transforms.H"
00050 #include "Image/fancynorm.H"
00051 #include "Parallel/pvisionTCP-defs.H"
00052 #include "Util/Assert.H"
00053 #include "Util/Timer.H"
00054 #include "Util/Types.H"
00055
00056 #include <signal.h>
00057
00058 static bool goforever = true;
00059
00060
00061 void terminate(int s) { LERROR("*** INTERRUPT ***"); goforever = false; }
00062
00063
00064 void computeCMAP(TCPmessage& msg, const PyramidType ptyp,
00065 const float ori, const float coeff,
00066 const int slave, nub::soft_ref<Beowulf>& b);
00067
00068
00069 void computeCMAP2(TCPmessage& msg, const PyramidType ptyp,
00070 const float ori, const float coeff,
00071 const int slave, nub::soft_ref<Beowulf>& b);
00072
00073
00074 void computeCMAP(const Image<float>& fima, const PyramidType ptyp,
00075 const float ori, const float coeff,
00076 const int slave, nub::soft_ref<Beowulf>& b, const int32 id);
00077
00078
00079
00080
00081 #define sml 2
00082 #define delta_min 3
00083 #define delta_max 4
00084 #define level_min 0
00085 #define level_max 2
00086 #define maxdepth (level_max + delta_max + 1)
00087 #define normtyp (VCXNORM_MAXNORM)
00088
00089
00090 #define IWEIGHT 1.0
00091 #define CWEIGHT 1.0
00092 #define OWEIGHT 1.0
00093 #define FWEIGHT 1.5
00094
00095
00096 int main(const int argc, const char **argv)
00097 {
00098 MYLOGVERB = LOG_INFO;
00099
00100
00101 ModelManager manager("Parallel Vision TCP Version 3 - Slave");
00102
00103
00104 nub::soft_ref<Beowulf>
00105 beo(new Beowulf(manager, "Beowulf Slave", "BeowulfSlave", false));
00106 manager.addSubComponent(beo);
00107
00108
00109 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00110
00111
00112 signal(SIGHUP, terminate); signal(SIGINT, terminate);
00113 signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00114 initRandomNumbers();
00115
00116
00117 TCPmessage rmsg;
00118 TCPmessage smsg;
00119 Image<float> previma;
00120 Timer tim;
00121
00122
00123 manager.start();
00124
00125
00126 while(goforever)
00127 {
00128 int32 rframe, raction, rnode = -1;
00129 if (beo->receive(rnode, rmsg, rframe, raction, 3))
00130 {
00131 LINFO("Frame %d, action %d from node %d", rframe, raction, rnode);
00132 tim.reset();
00133
00134
00135 switch(raction)
00136 {
00137 case BEO_INIT:
00138 {
00139
00140
00141 }
00142 break;
00143 case BEO_LUMINANCE:
00144 computeCMAP(rmsg, Gaussian5, 0.0, IWEIGHT, 0, beo);
00145 break;
00146 case BEO_FLICKER:
00147 {
00148
00149 Image<byte> ima = rmsg.getElementByteIma();
00150 Image<float> fima = ima;
00151
00152
00153 if (previma.initialized() == false) previma = fima;
00154 previma -= fima;
00155
00156
00157 computeCMAP(previma, Gaussian5, 0.0, FWEIGHT, 1, beo, rframe);
00158
00159
00160 previma = fima;
00161 }
00162 break;
00163 case BEO_REDGREEN:
00164 computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 2, beo);
00165 break;
00166 case BEO_BLUEYELLOW:
00167 computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 3, beo);
00168 break;
00169
00170 case BEO_ORI0:
00171 computeCMAP(rmsg, Oriented5, 0.0, OWEIGHT, 4, beo);
00172 break;
00173 case BEO_ORI15:
00174 computeCMAP(rmsg, Oriented5, 15.0, OWEIGHT, 5, beo);
00175 break;
00176 case BEO_ORI30:
00177 computeCMAP(rmsg, Oriented5, 30.0, OWEIGHT, 6, beo);
00178 break;
00179 case BEO_ORI45:
00180 computeCMAP(rmsg, Oriented5, 45.0, OWEIGHT, 7, beo);
00181 break;
00182 case BEO_ORI60:
00183 computeCMAP(rmsg, Oriented5, 60.0, OWEIGHT, 8, beo);
00184 break;
00185 case BEO_ORI75:
00186 computeCMAP(rmsg, Oriented5, 75.0, OWEIGHT, 9, beo);
00187 break;
00188 case BEO_ORI90:
00189 computeCMAP(rmsg, Oriented5, 90.0, OWEIGHT, 10, beo);
00190 break;
00191 case BEO_ORI105:
00192 computeCMAP(rmsg, Oriented5, 105.0, OWEIGHT, 11, beo);
00193 break;
00194 case BEO_ORI120:
00195 computeCMAP(rmsg, Oriented5, 120.0, OWEIGHT, 12, beo);
00196 break;
00197 case BEO_ORI135:
00198 computeCMAP(rmsg, Oriented5, 135.0, OWEIGHT, 13, beo);
00199 break;
00200 case BEO_ORI150:
00201 computeCMAP(rmsg, Oriented5, 150.0, OWEIGHT, 14, beo);
00202 break;
00203 case BEO_ORI165:
00204 computeCMAP(rmsg, Oriented5, 165.0, OWEIGHT, 15, beo);
00205 break;
00206 default:
00207 LERROR("Bogus action %d -- IGNORING.", raction);
00208 break;
00209 }
00210
00211 LINFO("Action %d, frame %d processed in %llums",
00212 raction, rframe, tim.get());
00213 }
00214 }
00215
00216 LINFO("done");
00217
00218
00219 manager.stop();
00220 return 0;
00221 }
00222
00223
00224 void computeCMAP(TCPmessage& msg, const PyramidType ptyp,
00225 const float ori, const float coeff,
00226 const int mapn, nub::soft_ref<Beowulf>& b)
00227 {
00228
00229 Image<byte> ima = msg.getElementByteIma();
00230 Image<float> fima = ima;
00231
00232 computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID());
00233
00234 }
00235
00236
00237 void computeCMAP2(TCPmessage& msg, const PyramidType ptyp,
00238 const float ori, const float coeff,
00239 const int mapn, nub::soft_ref<Beowulf>& b)
00240 {
00241 Image<byte> ima1 = msg.getElementByteIma();
00242 Image<byte> ima2 = msg.getElementByteIma();
00243 Image<float> fima = ima1 - ima2;
00244
00245 computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID());
00246 }
00247
00248
00249 void computeCMAP(const Image<float>& fima, const PyramidType ptyp,
00250 const float ori, const float coeff,
00251 const int mapn, nub::soft_ref<Beowulf>& b, const int32 id)
00252 {
00253
00254
00255
00256 ImageSet<float> pyr = buildPyrGeneric(fima, 0, maxdepth, ptyp, ori);
00257
00258
00259 Image<float> cmap(pyr[sml].getDims(), ZEROS);
00260
00261
00262
00263
00264 for (int delta = delta_min; delta <= delta_max; delta ++)
00265 for (int lev = level_min; lev <= level_max; lev ++)
00266 {
00267 Image<float> tmp = centerSurround(pyr, lev, lev + delta, true);
00268 tmp = downSize(tmp, cmap.getWidth(), cmap.getHeight());
00269 inplaceAddBGnoise(tmp, 255.0);
00270 tmp = maxNormalize(tmp, MAXNORMMIN, MAXNORMMAX, normtyp);
00271 cmap += tmp;
00272 }
00273 if (normtyp == VCXNORM_MAXNORM)
00274 cmap = maxNormalize(cmap, MAXNORMMIN, MAXNORMMAX, normtyp);
00275 else
00276 cmap = maxNormalize(cmap, 0.0f, 0.0f, normtyp);
00277
00278
00279
00280
00281 cmap *= coeff;
00282
00283
00284 TCPmessage smsg(id, BEO_CMAP | (mapn << 16));
00285 smsg.addImage(cmap);
00286
00287
00288
00289
00290 int qlen = b->nbReceived();
00291 smsg.setETI(float(qlen) * 0.005);
00292
00293
00294 b->send(-1, smsg);
00295
00296
00297 }
00298
00299
00300
00301
00302
00303