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
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 computeCMAP(previma, Gaussian5, 0.0, FWEIGHT, 1, beo, rframe);
00156 previma = fima;
00157 }
00158 break;
00159 case BEO_REDGREEN:
00160 computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 2, beo);
00161 break;
00162 case BEO_BLUEYELLOW:
00163 computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 3, beo);
00164 break;
00165 case BEO_ORI0:
00166 computeCMAP(rmsg, Oriented5, 0.0, OWEIGHT, 4, beo);
00167 break;
00168 case BEO_ORI45:
00169 computeCMAP(rmsg, Oriented5, 45.0, OWEIGHT, 5, beo);
00170 break;
00171 case BEO_ORI90:
00172 computeCMAP(rmsg, Oriented5, 90.0, OWEIGHT, 6, beo);
00173 break;
00174 case BEO_ORI135:
00175 computeCMAP(rmsg, Oriented5, 135.0, OWEIGHT, 7, beo);
00176 break;
00177 default:
00178 LERROR("Bogus action %d -- IGNORING.", raction);
00179 break;
00180 }
00181
00182 LINFO("Action %d, frame %d processed in %llums",
00183 raction, rframe, tim.get());
00184 }
00185 }
00186
00187
00188 manager.stop();
00189 return 0;
00190 }
00191
00192
00193 void computeCMAP(TCPmessage& msg, const PyramidType ptyp,
00194 const float ori, const float coeff,
00195 const int mapn, nub::soft_ref<Beowulf>& b)
00196 {
00197 Image<byte> ima = msg.getElementByteIma();
00198 Image<float> fima = ima;
00199
00200 computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID());
00201 }
00202
00203
00204 void computeCMAP2(TCPmessage& msg, const PyramidType ptyp,
00205 const float ori, const float coeff,
00206 const int mapn, nub::soft_ref<Beowulf>& b)
00207 {
00208 Image<byte> ima1 = msg.getElementByteIma();
00209 Image<byte> ima2 = msg.getElementByteIma();
00210 Image<float> fima = ima1 - ima2;
00211
00212 computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID());
00213 }
00214
00215
00216 void computeCMAP(const Image<float>& fima, const PyramidType ptyp,
00217 const float ori, const float coeff,
00218 const int mapn, nub::soft_ref<Beowulf>& b, const int32 id)
00219 {
00220
00221 ImageSet<float> pyr = buildPyrGeneric(fima, 0, maxdepth, ptyp, ori);
00222
00223
00224 Image<float> cmap(pyr[sml].getDims(), ZEROS);
00225
00226
00227 for (int delta = delta_min; delta <= delta_max; delta ++)
00228 for (int lev = level_min; lev <= level_max; lev ++)
00229 {
00230 Image<float> tmp = centerSurround(pyr, lev, lev + delta, true);
00231 tmp = downSize(tmp, cmap.getWidth(), cmap.getHeight());
00232 inplaceAddBGnoise(tmp, 255.0);
00233 tmp = maxNormalize(tmp, MAXNORMMIN, MAXNORMMAX, normtyp);
00234 cmap += tmp;
00235 }
00236 if (normtyp == VCXNORM_MAXNORM)
00237 cmap = maxNormalize(cmap, MAXNORMMIN, MAXNORMMAX, normtyp);
00238 else
00239 cmap = maxNormalize(cmap, 0.0f, 0.0f, normtyp);
00240
00241
00242 cmap *= coeff;
00243
00244
00245 TCPmessage smsg(id, BEO_CMAP | (mapn << 16));
00246 smsg.addImage(cmap);
00247
00248
00249 int qlen = b->nbReceived();
00250 smsg.setETI(float(qlen) * 0.005);
00251
00252
00253 b->send(-1, smsg);
00254 }
00255
00256
00257
00258
00259
00260