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 
00044   defInterleavedYUVGenerator = new InterleavedYUVGenerator(EventBase::visRawCameraEGID,visRawCameraSID,visInterleaveSID,RawCameraGenerator::CHAN_Y,RawCameraGenerator::CHAN_U,RawCameraGenerator::CHAN_V);
00045 
00046   defColorJPEGGenerator = new JPEGGenerator(EventBase::visInterleaveEGID,visInterleaveSID,visColorJPEGSID,JPEGGenerator::SRC_AUTO);
00047   defColorJPEGGenerator->setName("ColorJPEGGenerator");
00048 
00049   defGrayscaleJPEGGenerator = new JPEGGenerator(EventBase::visRawCameraEGID,visRawCameraSID,visGrayscaleJPEGSID,JPEGGenerator::SRC_AUTO);
00050   defGrayscaleJPEGGenerator->setName("GrayscaleJPEGGenerator");
00051 
00052   // the hardware level CDT generator allows faster, but less flexible
00053   // segmenting it still needs a little work though before it can be
00054   // hooked up to the CMVision RLE generator.  See CDTGenerator class notes.
00055   // defSegmentedColorGenerator = new CDTGenerator(numSystemLayers,numLayers,EventBase::visOFbkEGID,0,visSegmentSID);
00056   SegmentedColorGenerator * segcol = new SegmentedColorGenerator(EventBase::visRawCameraEGID,visRawCameraSID,visSegmentSID);
00057   defSegmentedColorGenerator = segcol;
00058   segcol->loadColorInfo(config->vision.colors);
00059   for(unsigned int i=0; i<config->vision.thresh.size(); i++)
00060     segcol->loadThresholdMap(config->vision.thresh[i]);
00061 
00062   defRLEGenerator = new RLEGenerator(EventBase::visSegmentEGID,visSegmentSID,visRLESID);
00063   
00064   defRegionGenerator = new RegionGenerator(EventBase::visRLEEGID,visRLESID,visRegionSID);
00065   
00066   // for lack of a better idea, the object recognizers below will all
00067   // use the config->vision.rlecam_channel for picking the threshold
00068   // file to use
00069   // note that this is done here just once with the initial value, but
00070   // the detectors won't get reloaded if you change the rlecam_channel
00071   // later on
00072 
00073   // these names match up with /ms/config/default.col - the default
00074   // color information... if that changes, these should change too
00075   unsigned int threshChan=config->vision.rlecam_channel;
00076 
00077   // higher value reduce false events, but increase reaction time [0-inf]
00078   unsigned int noiseFiltering=1;
00079 
00080   // lower values increase sensitivity (and noise) [0-1]
00081   float confidenceThreshold=.8;
00082 
00083   unsigned int pinkIdx=segcol->getColorIndex("red");
00084   if(pinkIdx!=-1U) {
00085     pball = new BallDetectionGenerator(EventBase::visRegionEGID,visRegionSID,visPinkBallSID,pinkIdx,threshChan,noiseFiltering,confidenceThreshold);
00086     pball->setName("PinkBallDetectionGenerator");
00087   }
00088   unsigned int blueIdx=segcol->getColorIndex("blue");
00089   if(blueIdx!=-1U) {
00090     bball = new BallDetectionGenerator(EventBase::visRegionEGID,visRegionSID,visBlueBallSID,blueIdx,threshChan,noiseFiltering,confidenceThreshold);
00091     bball->setName("BlueBallDetectionGenerator");
00092   }
00093   unsigned int skinIdx=segcol->getColorIndex("brown");
00094   if(skinIdx!=-1U) {
00095     handball = new BallDetectionGenerator(EventBase::visRegionEGID,visRegionSID,visHandSID,skinIdx,threshChan,noiseFiltering,confidenceThreshold);
00096     handball->setName("HandBallDetectionGenerator");
00097   }
00098 }
00099 
00100 ControlBase*
00101 StartupBehavior::SetupVision() {
00102   addItem(new ControlBase("Vision Pipeline","Start/Stop stages of the vision pipeline"));
00103   startSubMenu();
00104   { 
00105     addItem((new BehaviorSwitchControlBase(defRawCameraGenerator))->start());
00106     addItem((new BehaviorSwitchControlBase(defInterleavedYUVGenerator))->start());
00107     addItem((new BehaviorSwitchControlBase(defColorJPEGGenerator))->start());
00108     addItem((new BehaviorSwitchControlBase(defGrayscaleJPEGGenerator))->start());
00109     if(config->vision.colors!="" && config->vision.thresh.size()>0)
00110       addItem((new BehaviorSwitchControlBase(defSegmentedColorGenerator))->start());
00111     else
00112       addItem(new BehaviorSwitchControlBase(defSegmentedColorGenerator));
00113     addItem((new BehaviorSwitchControlBase(defRLEGenerator))->start());
00114     addItem((new BehaviorSwitchControlBase(defRegionGenerator))->start());
00115     addItem((new BehaviorSwitchControlBase(pball))->start());
00116     addItem((new BehaviorSwitchControlBase(bball))->start());
00117     addItem((new BehaviorSwitchControlBase(handball))->start());
00118   }
00119   return endSubMenu();
00120 }

Tekkotsu v2.1
Generated Tue Mar 16 23:19:15 2004 by Doxygen 1.3.5