TV_Lane.H
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 #ifndef TV_LANE
00038 #define TV_LANE
00039 #include "Image/OpenCVUtil.H"
00040 #include "Component/ModelComponent.H"
00041 #include "Component/ModelParam.H"
00042
00043 #include "Robots/RobotBrain/RobotBrainComponent.H"
00044 #include "Util/Timer.H"
00045
00046 #include "Ice/RobotBrainObjects.ice.H"
00047 #include "Ice/RobotSimEvents.ice.H"
00048 #include <IceUtil/Thread.h>
00049
00050
00051 #include "Robots/Beobot2/LaneFollowing/TV_Lane/SaliencyMT.H"
00052 #include "Robots/Beobot2/BeoCommon.H"
00053
00054 #include "Media/FrameSeries.H"
00055
00056 #include "Image/Image.H"
00057 #include "Image/Point3D.H"
00058 #include "Raster/Raster.H"
00059
00060 #include <vector>
00061 #include "Transport/FrameInfo.H"
00062 #include "Gist/SuperPixel.H"
00063
00064
00065 typedef struct _RegionInformation
00066 {
00067 uint start;
00068 uint end;
00069
00070 float minDistance;
00071 uint minIndex;
00072 }
00073 RegionInformation;
00074
00075
00076 class imageDB
00077 {
00078 std::string path;
00079 int start;
00080 int end;
00081 int current;
00082 public:
00083 imageDB(){}
00084
00085 imageDB(std::string p,int s,int e)
00086 {
00087 start = s;
00088 end = e;
00089 path = p;
00090 current = s;
00091 }
00092 Image<PixRGB<byte> > nextImg()
00093 {
00094 std::string imgpath = sformat("%s%05d.ppm",path.c_str(),current);
00095 LDEBUG("Image path is %s",imgpath.c_str());
00096 if(current++ > end)
00097 current = start;
00098 return Raster::ReadRGB(imgpath.c_str());
00099 }
00100 ~imageDB(){}
00101 };
00102
00103
00104
00105 class kalman_filter
00106 {
00107 float est_var,sensor_var;
00108 float k;
00109 float est_x;
00110 public:
00111 kalman_filter(float ini_ev,float ini_sv)
00112 {
00113 est_var = ini_ev;
00114 sensor_var = ini_sv;
00115 k = est_var/(est_var + sensor_var);
00116 est_x = 0;
00117 }
00118 float update(float measure)
00119 {
00120 if(est_x == 0)
00121 {
00122 est_x = measure;
00123 return est_x;
00124 }
00125 est_x = est_x + 10*k*(measure - est_x);
00126 est_var = est_var*sensor_var/(est_var+sensor_var);
00127 k = est_var/(est_var+sensor_var);
00128 return est_x;
00129 }
00130
00131 };
00132
00133 class TV_Lane: public RobotBrainComponent
00134 {
00135 public:
00136
00137 TV_Lane(OptionManager& mgr,
00138 const std::string& descrName = "TV_Lane",
00139 const std::string& tagName = "TV_Lane");
00140
00141 ~TV_Lane();
00142
00143 virtual void evolve();
00144
00145
00146 virtual void updateMessage (const RobotSimEvents::EventMessagePtr& eMsg, const Ice::Current&);
00147
00148 virtual void registerTopics();
00149
00150 void start1();
00151
00152 private:
00153
00154 void openDB(const std::string& path);
00155 void loadFrame();
00156
00157 void loadDB(const std::string& path);
00158 void drawState();
00159 void fitLine(std::vector<Point2D<int> > points, Point2D<int>&p1,Point2D<int>&p2);
00160 Image<PixRGB<byte> > getSuperPixel(Image<PixRGB<byte> > img);
00161 Image<PixRGB<byte> > getCannyEdge(Image<PixRGB<byte> > img, Image<PixRGB<byte> > &rawCannyImg);
00162 Image<PixRGB<byte> > getSaliency(Image<PixRGB<byte> > img);
00163 int getVotingCount(Image<PixRGB<byte> > img,int topX,int topY,int windowSize,PixRGB<byte> bgColor);
00164 PixRGB<byte> getBackgroundColor(Image<PixRGB<byte> >img);
00165 Image<float> getVotingBlock(Image<PixRGB<byte> > img);
00166 Image<float> updateVoteBlock(Image<float> map);
00167 Image<float> itsVoteMap;
00168
00169 Image<PixRGB<byte> > itsCurrImg;
00170 Image<PixRGB<byte> > itsProcImg;
00171 nub::soft_ref<SaliencyMT> itsSmt;
00172 nub::soft_ref<OutputFrameSeries> itsOfs;
00173 nub::soft_ref<InputFrameSeries> itsIfs;
00174 imageDB itsImageDB;
00175 kalman_filter itsKf;
00176 int itsKfx;
00177
00178 Image<PixRGB<byte> > itsDispImg;
00179
00180 void updateMotor(double tran, double rot);
00181
00182 IceUtil::Mutex its_Curr_Img_mutex;
00183 IceUtil::Mutex its_Curr_Mtr_mutex;
00184 int itsCurrImgID;
00185 double itsRcTransSpeed;
00186 double itsRcRotSpeed;
00187 int itsRemoteMode;
00188 int itsPrevProcImgID;
00189 Timer itsTimer;
00190
00191
00192
00193 double getNormal(double u, double s, double x){
00194 double coefficient = 1.0/sqrt(2.0 * M_PI * s*s);
00195 return coefficient * exp(-(x-u)*(x-u)/(2.0 * s*s));
00196 }
00197 double getNormalWeight(double x){
00198 double u = 0;
00199 double s = 1;
00200 return getNormal(u,s,x)/getNormal(u,s,0);
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 };
00236 #endif
00237
00238
00239
00240
00241
00242