Homepage Demos Overview Downloads Tutorials Reference
Credits

StartupBehavior_SetupVision.cc

Go to the documentation of this file.
00001 #include "StartupBehavior.h"
00002 
00003 #include "Shared/ProjectInterface.h"
00004 #include "Shared/Config.h"
00005 
00006 #include "Behaviors/Controls/BehaviorSwitchControl.h"
00007 
00008 #include "Vision/RawCameraGenerator.h"
00009 #include "Vision/InterleavedYUVGenerator.h"
00010 #include "Vision/JPEGGenerator.h"
00011 #include "Vision/SegmentedColorGenerator.h"
00012 #include "Vision/RLEGenerator.h"
00013 #include "Vision/RegionGenerator.h"
00014 #include "Vision/BallDetectionGenerator.h"
00015 #include "Vision/CDTGenerator.h"
00016 
00017 using namespace ProjectInterface;
00018 
00019 BallDetectionGenerator * pball=NULL;
00020 BallDetectionGenerator * bball=NULL;
00021 BallDetectionGenerator * handball=NULL;
00022 
00023 /*! We set the default vision generators and source IDs here.
00024  *
00025  * The vis*SID and def*Generator variables are defined in
00026  * ProjectInterface.  You can reassign their values as you see fit,
00027  * which allows you to reorganize and adapt the vision pipeline, but
00028  * still retain the ability of the included demo behaviors to access
00029  * vision information.
00030  */
00031 void
00032 StartupBehavior::initVision() {
00033   //The value you set here will define the number of resolution layers available throughout the vision pipeline
00034   //If you change this value, you should modify the *Layer variables in ProjectInterface (if you want to use them)
00035   unsigned int numLayers=6;
00036 
00037   //The top level layer will be double resolution
00038   //This will set how many real layers are provided by the system (3 in Aperios)
00039   //Any other layers will be subsamples of the lowest resolution system resolution
00040   unsigned int numSystemLayers=3;
00041 
00042   defRawCameraGenerator = new RawCameraGenerator(numSystemLayers,numLayers,EventBase::visOFbkEGID,0,visRawCameraSID);
00043   defRawCameraGenerator->DoStart();
00044   spawned.push_back(defRawCameraGenerator);
00045 
00046   defInterleavedYUVGenerator = new InterleavedYUVGenerator(EventBase::visRawCameraEGID,visRawCameraSID,visInterleaveSID,RawCameraGenerator::CHAN_Y,RawCameraGenerator::CHAN_U,RawCameraGenerator::CHAN_V);
00047   defInterleavedYUVGenerator->DoStart();
00048   spawned.push_back(defInterleavedYUVGenerator);
00049 
00050   defColorJPEGGenerator = new JPEGGenerator(EventBase::visInterleaveEGID,visInterleaveSID,visColorJPEGSID,JPEGGenerator::SRC_AUTO);
00051   defColorJPEGGenerator->DoStart();
00052   defColorJPEGGenerator->setName("ColorJPEGGenerator");
00053   spawned.push_back(defColorJPEGGenerator);
00054 
00055   defGrayscaleJPEGGenerator = new JPEGGenerator(EventBase::visRawCameraEGID,visRawCameraSID,visGrayscaleJPEGSID,JPEGGenerator::SRC_AUTO);
00056   defGrayscaleJPEGGenerator->DoStart();
00057   defGrayscaleJPEGGenerator->setName("ColorGrayscaleGenerator");
00058   spawned.push_back(defGrayscaleJPEGGenerator);
00059 
00060   // the hardware level CDT generator allows faster, but less flexible
00061   // segmenting it still needs a little work though before it can be
00062   // hooked up to the CMVision RLE generator.  See CDTGenerator class notes.
00063   // defSegmentedColorGenerator = new CDTGenerator(numSystemLayers,numLayers,EventBase::visOFbkEGID,0,visSegmentSID);
00064   SegmentedColorGenerator * segcol = new SegmentedColorGenerator(EventBase::visRawCameraEGID,visRawCameraSID,visSegmentSID);
00065   defSegmentedColorGenerator = segcol;
00066   segcol->loadColorInfo(config->vision.colors);
00067   for(unsigned int i=0; i<config->vision.thresh.size(); i++)
00068     segcol->loadThresholdMap(config->vision.thresh[i]);
00069   if(config->vision.colors!="" && config->vision.thresh.size()>0) {
00070     defSegmentedColorGenerator->DoStart();
00071     spawned.push_back(defSegmentedColorGenerator);
00072   }
00073 
00074   defRLEGenerator = new RLEGenerator(EventBase::visSegmentEGID,visSegmentSID,visRLESID);
00075   defRLEGenerator->DoStart();
00076   spawned.push_back(defRLEGenerator);
00077   
00078   defRegionGenerator = new RegionGenerator(EventBase::visRLEEGID,visRLESID,visRegionSID);
00079   defRegionGenerator->DoStart();
00080   spawned.push_back(defRegionGenerator);
00081   
00082   // for lack of a better idea, the object recognizers below will all
00083   // use the config->vision.rlecam_channel for picking the threshold
00084   // file to use
00085   // note that this is done here just once with the initial value, but
00086   // the detectors won't get reloaded if you change the rlecam_channel
00087   // later on
00088 
00089   // these names match up with /ms/config/default.col - the default
00090   // color information... if that changes, these should change too
00091   unsigned int threshChan=config->vision.rlecam_channel;
00092 
00093   // higher value reduce false events, but increase reaction time [0-inf]
00094   unsigned int noiseFiltering=1;
00095 
00096   // lower values increase sensitivity (and noise) [0-1]
00097   float confidenceThreshold=.8;
00098 
00099   unsigned int pinkIdx=segcol->getColorIndex("red");
00100   if(pinkIdx!=-1U) {
00101     pball = new BallDetectionGenerator(EventBase::visRegionEGID,visRegionSID,visPinkBallSID,pinkIdx,threshChan,noiseFiltering,confidenceThreshold);
00102     pball->setName("PinkBallDetectionGenerator");
00103     pball->DoStart();
00104     spawned.push_back(pball);
00105   }
00106   unsigned int blueIdx=segcol->getColorIndex("blue");
00107   if(blueIdx!=-1U) {
00108     bball = new BallDetectionGenerator(EventBase::visRegionEGID,visRegionSID,visBlueBallSID,blueIdx,threshChan,noiseFiltering,confidenceThreshold);
00109     pball->setName("BlueBallDetectionGenerator");
00110     bball->DoStart();
00111     spawned.push_back(bball);
00112   }
00113   unsigned int skinIdx=segcol->getColorIndex("brown");
00114   if(skinIdx!=-1U) {
00115     handball = new BallDetectionGenerator(EventBase::visRegionEGID,visRegionSID,visHandSID,skinIdx,threshChan,noiseFiltering,confidenceThreshold);
00116     pball->setName("HandBallDetectionGenerator");
00117     handball->DoStart();
00118     spawned.push_back(handball);
00119   }
00120 }
00121 
00122 ControlBase*
00123 StartupBehavior::SetupVision() {
00124   addItem(new ControlBase("Vision Pipeline","Start/Stop stages of the vision pipeline"));
00125   startSubMenu();
00126   { 
00127     addItem(new BehaviorSwitchControlBase(defRawCameraGenerator));
00128     addItem(new BehaviorSwitchControlBase(defInterleavedYUVGenerator));
00129     addItem(new BehaviorSwitchControlBase(defColorJPEGGenerator));
00130     addItem(new BehaviorSwitchControlBase(defGrayscaleJPEGGenerator));
00131     addItem(new BehaviorSwitchControlBase(defSegmentedColorGenerator));
00132     addItem(new BehaviorSwitchControlBase(defRLEGenerator));
00133     addItem(new BehaviorSwitchControlBase(defRegionGenerator));
00134     addItem(new BehaviorSwitchControlBase(pball));
00135     addItem(new BehaviorSwitchControlBase(bball));
00136     addItem(new BehaviorSwitchControlBase(handball));
00137   }
00138   return endSubMenu();
00139 }

Tekkotsu v2.0
Generated Wed Jan 21 03:20:30 2004 by Doxygen 1.3.4