SaliencyModuleI.C

00001 #include "Robots/SeaBeeIII/SaliencyModuleI.H"
00002 #include "Robots/RobotBrain/RobotBrainComponent.H"
00003 #include "Component/ModelParam.H"
00004 #include "Component/ModelOptionDef.H"
00005 #include "Image/MathOps.H"
00006 
00007 #ifndef SALIENCYMODULEI_C
00008 #define SALIENCYMODULEI_C
00009 
00010 const ModelOptionCateg MOC_SaliencyModule = {
00011   MOC_SORTPRI_3, "SeaBee Saliency Computer Related Options"
00012 };
00013 
00014 const ModelOptionDef OPT_ImageDescr =
00015 { MODOPT_ARG(std::string), "ImageDescr", &MOC_SaliencyModule, OPTEXP_CORE,
00016   "Description of the image on which we are computing saliency.\n"
00017     "(Generally, use Camera0, Camera1, etc...)",
00018   "image-descr", '\0', "<string>", "Camera0" };
00019 
00020 
00021 // ######################################################################
00022 SaliencyModuleI::SaliencyModuleI(OptionManager& mgr,
00023     const std::string& descrName, const std::string& tagName) :
00024   VisionBrainComponentI(mgr, descrName, tagName),
00025   itsEvc(new EnvVisualCortex(mgr)),
00026   itsImageDescr(&OPT_ImageDescr, this, 0),
00027   itsRunning(true)
00028 {
00029   //Add the visual cortex
00030   addSubComponent(itsEvc);
00031 }
00032 
00033 // ######################################################################
00034 void SaliencyModuleI::registerTopics()
00035 {
00036   LINFO("Registering Saliency Point Message");
00037   this->registerPublisher("SalientPointMessageTopic");
00038   registerVisionTopics();
00039 }
00040 
00041 // ######################################################################
00042 void SaliencyModuleI::updateFrame(Image<PixRGB<byte> > img, string cameraId)
00043 {
00044         bool isFwdCamera = false;
00045         if(cameraId == "FwdCamera")
00046                 isFwdCamera = true;
00047 
00048         updateFrame(img, isFwdCamera);
00049 
00050 }
00051 
00052 // ######################################################################
00053 void SaliencyModuleI::updateFrame(Image<PixRGB<byte> > img, bool isFwdCamera)
00054 {
00055   if(itsRunning)
00056   {
00057     if(img.initialized())
00058     {
00059       // Input the new image into the envision visual cortex
00060       itsEvc->input(img);
00061       // Grab the visual cortex output map (saliency map)
00062       Image<byte> vcxMap = itsEvc->getVCXmap();
00063       Point2D<int> pt;
00064       byte saliency;
00065       findMax(vcxMap, pt, saliency);
00066       pt.i = pt.i << itsEvc->getMapLevel();
00067       pt.j = pt.j << itsEvc->getMapLevel();
00068 
00069       Point2D<int> imgCenter = Point2D<int>(img.getWidth(),img.getHeight());
00070       Point2D<int> err = pt - imgCenter;
00071 
00072                         if(!itsOfs->isVoid())
00073                         {
00074                                 drawCircle(img,pt,5,PixRGB<byte>(0,0,255));
00075                                 itsOfs->writeRGB(img, "Saliency Module Image",
00076                                                 FrameInfo("Saliency Module Image", SRC_POS));
00077 
00078                                 itsOfs->updateNext();
00079                         }
00080 
00081       RobotSimEvents::SalientPointMessagePtr msg = new RobotSimEvents::SalientPointMessage;
00082       msg->x = float(pt.i)/float(img.getWidth());
00083       msg->y = float(pt.j)/float(img.getHeight());
00084       msg->saliency = saliency;
00085       msg->imageDescr = itsImageDescr.getVal();
00086 
00087                         LINFO("Calculated Saliency");
00088       this->publish("SalientPointMessageTopic", msg);
00089 
00090     }
00091     else
00092     {
00093       LERROR("Image Not Initialized!");
00094     }
00095 
00096   }
00097 }
00098 
00099 #endif
00100 
Generated on Sun May 8 08:41:38 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3